(async () => { set(await get()); })();
get().then(r => set(r));
Ignoring error handling I'll often choose the second option. (async () => { set(await get()); })();
get().then(r => set(r));
Ignoring error handling I'll often choose the second option. get().then(set)
It's the try/catch blocks that make async/await truly worse than native promises. I use them sparingly because so often the .then syntax is both clearer and terser. get()
.then(handleResult)
.catch(useFallbackResult)
.then(updateState)
I prefer concision and functional expressiveness because it reduces the surface area for writing buggy code. Much like how using map instead writing a for loop can eliminate out of range index bugs, chaining promises brings useful guarantees about how the code I do write can be interpreted. const result = await get()
set(result)
But you do you.Current node and console have top level await BTW.
In other words, your complaints have disappeared in node, and will soon in browsers: https://github.com/tc39/proposal-top-level-await
So yes:
set(await get())