DEV Community

Discussion on: Using a Promise in a click eventListener - more than once.

Collapse
 
pankajpatel profile image
Pankaj Patel

You can not reuse the promise to go back to the Pending state, but you can create a new one. You can write another generator function to get a new promise on the Fly.

And to deal with returning undefined in async/await; you can do the following:

const data = await Promise.resolve(getSomePromise(someParam));

What Promise.resolve does is that it converts a non-promise value given to it to a Promisified value and hence you can await on it; and if the value passed to Promise.resolve is already a promise, i.e. then-able value; it will continue working as a regular value

Collapse
 
alittlebyte profile image
Vlad • Edited

Yes, thank you, this is exactly what I need!
One question, though... how would I write a generator function for Promises?
Search returns nothing, besides information on the Promises themselves.
Shouldn't my existing returnCollectionsId() already work as a generator? From how I see it, it should return a new Promise everytime it is called, but it doesn't. So that's the part I don't get.
Just send an article my way that explains the topic further. Can't find one :\ Thank you again!