3 ms·
I wrote the following, completely innocently: return when.all(promises).yield(true);
by stevage 7y ago
I wrote the following, completely innocently:
return when.all(promises).yield(true);
- ohvirginia 7y agoExcept for the return to happen when that's true, you'd need an await. At least in JS.
- acarl005 7y agoNot if it's returned by an async function. In JS, async functions automatically await promises that are returned.
- deleted 7y ago[deleted]
- emilecantin 7y agoThat's not actually right. An async function will always return a promise, so if you return a promise directly it's indeed pretty much the same as if you return a promise that waits on that promise; it's the calling function that actually awaits on the returned promise. The main difference would be error handling: if you have a catch block that returns a different value, returning the promise directly would actually throw in the calling function, whereas if you "return await", it's going to get caught in your catch block, resolving the promise to your own custom value. Found a detailed explanation here: https://jakearchibald.com/2017/await-vs-return-vs-return-await/ https://jakearchibald.com/2017/await-vs-return-vs-return-awa...