'return await promise' vs 'return promise' in JavaScript
dmitripavlutin.com · 737 words · saved by 1 readers
Is there any difference between using 'return await promise' and 'return promise' in asynchronous JavaScript functions?
'return await promise' vs 'return promise' in JavaScript Posted August 10, 2021 javascript promise async -- Comments When returning from a promise from an asynchronous function, you can wait for that promise to resolve return await promise , or you can return it directly return promise : async function func1() { const promise = asyncOperation(); return await promise; } // vs async function func2() { const promise = asyncOperation(); return promise; } You'll see shortly that both expressions do work. However, are there cases when these expressions behave differently? Let's find out! 1. Same beh
related reading
- Reading 15: Promisesweb.mit.edu
- Microtasks and event looptr.javascript.info
- Promise - JavaScript | MDNdeveloper.mozilla.org
- TypeScript Structured Concurrencythecandidstartup.org
- Futures and promises - Wikipediaen.wikipedia.org
- JavaScript Async Promisesw3schools.com
- What the heck is the event loop anyway? | Philip Roberts | JSConf EUyoutube.com
- Notes on structured concurrency, or: Go statement considered harmful - njs blogvorpus.org
- 5 Differences Between Arrow and Regular Functionsdmitripavlutin.com
- (Quite) A Few Words About Asyncyoric.github.io
- The Event Loop and Callback Hell - Wes Boswesbos.com
- A Design Space Exploration of Async/Awaitcel.cs.brown.edu