sync function x() {
const taco = getTaco() // getTaco returns Promise<Taco>, but taco automatically resolves it in a sync function
// Similarly, you can tell it to not wait
const ptaco = nowait getTaco();
// ptaco is a Promise<Taco>
const taco2 = ptaco; // taco2 is a Taco because the ptaco symbol is treated like (await ptaco) without nowait
// Also, since ptaco has already "awaited", future
// access would be 0 delay as it's basically a resolved promise.
}
Of course, similar to an async function, sync functions would also return a promise.Probably a dumb idea but I would use it personally.
I worked with guys that started after async/await.
The new guys just think of everything like it's synchronous. They don't understand Promises. They never look at code and think "I can run this in parallel with Promise.all and a reducer". They just await each thing one at a time.
So, I'm not sure the async/await annotations are really helping us when devs just use them like decorations that just have to be there for it to work.
await slowThingOne();
await slowThingTwo();
but these execute in parallel, awaiting until both are finished (the "good way"): await Promise.all([slowThingOne(), slowThingTwo()]);But you gather them by using:
`await Promise.allSettled([promise1, promise2, promise3])`
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
I run into subtle bugs all the time due to missing awaits, it's incredibly frustrating.
[1]: https://hyperscript.org/posts/2021-04-06-aysnc-transparency-...
If you use TS, ESLint's `no-floating-promises` rule (or the equivalent in other linters) is _such_ a requirement