Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise resolving question #114

Closed
jgarciallamas opened this issue Jan 12, 2021 · 1 comment
Closed

Promise resolving question #114

jgarciallamas opened this issue Jan 12, 2021 · 1 comment

Comments

@jgarciallamas
Copy link

Hi Kent,

I hope you are doing well despite the situation.

 Regarding the exercise, ./src/exercise/03.extra-2.js, caching in a context provider, I just wanted to ask you about this chunk of code:

In the 03.extra-2.js file

image

In the utils.js file

image

When the data information about one particular pokemon is not in the cache, then the run function is called. As far as I can understand, and this is my doubt, it seems as if we are resolving the same promise twice, I think in order to sync the async call of the API and then store the information in cache. Are we technically resolving the promise twice? If this is the case, could we have any kind of issue by doing that?

image

image

Thank you very much in advance Kent for any kind of comment.
Jose

@kentcdodds
Copy link
Member

Hi @jgarciallamas, remember that simply attaching .then onto a promise does not "resolve" the promise. It's simply a way to say: "when this promise is resolved, do this." So you can do:

const promise = Promise.resolve()

promise.then(() => {})
promise.then(() => {})
promise.then(() => {})
promise.then(() => {})
promise.then(() => {})

And that promise is only resolved once. Also, you can only ever resolve a promise once.

I hope that helps clear things up. If you have further questions, you're welcome to join me during office hours 👍 Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants