question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cache.dispatch use async/await

See original GitHub issue
cache.dispatch = async (...args) => {
    const type = argsToString(args)

    const timeout = getTimeout(args, option)
    if (timeout) {
      const now = Date.now()
      if (!timeoutCache.has(type)) {
        timeoutCache.set(type, now)
      } else {
        const timeoutOfCurrentType = timeoutCache.get(type)
        // console.log(now - timeout, timeoutOfCurrentType)
        if (now - timeout > timeoutOfCurrentType) {
          cache.delete(type)
          timeoutCache.delete(type)
        }
      }
    }

    if (!cache.has(type)) {
      cache.set(type, await store.dispatch.apply(store, args))
    }

cache.dispatch 使用async/await,当dispatch报错时不set cache?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
VitorLuizCcommented, Nov 29, 2018

Save Promise as cache value is smaller, easier and less invasive than intercept it’s resolution/rejection reason. But, maybe is not the right choice, so I’ll create another issue with this dicussion.

0reactions
wcxaacommented, Nov 29, 2018

VitorLuizC is right.

I know it caches promise, but why it is necessary to cache a rejected promise ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my redux app not caching an async api call in redux ...
1. You might need a conditional in useEffect -- only dispatch if selectAllCountries. · If I take selectAllCountrires.data away from the useEffect ...
Read more >
JavaScript Async - Cache - I Programmer
To store a new key/value pair in the cache you would use either: await myCache.add(request);. which loads the response from request and stores ......
Read more >
Async/Await - Best Practices in Asynchronous Programming
Async void methods have different composing semantics. Async methods returning Task or Task<T> can be easily composed using await, Task.WhenAny, Task.
Read more >
Async actions in bare Redux with Thunk or custom middleware
Learn how to manage asynchronous actions in React apps with Redux Toolkit, or a bare Redux implementation with custom middleware.
Read more >
Dispatch This: Using Apollo Client 3 as a State Management ...
Forming and sending the request · Updating async states (loading, error, data) · Normalizing and caching the response · Saving bandwidth by ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found