4 ms·
Some examples of when I don't immediately await a function that returns a promise: 1. I pass it into Promise.all(). This one is a little obvious but I think it
by treve 4y ago
Some examples of when I don't immediately await a function that returns a promise:
1. I pass it into Promise.all(). This one is a little obvious but I think it counts as you pass in non-awaited promises.
2. I store the promise I receive in a variable, that I can re-use to de-duplicate multiple in-progress calls.
3. I anticipate a future call, and fetch data in the background.
Those are some real examples I've used, but I can also image my HTTP server kicks off some process that's not consequential for the current request, which would also happened asynchronously (and maybe immediately return a 202. My HTTP framework doesn't use callbacks unlike express so functions need to return to send a response).
If you use React, calls in useEffect are also typically not awaited because the callback to useEffect does not support async functions.
I'd generally agree though that most of my code is also very linear, and the few places I need to weirder stuff tends be in the libraries I maintain.