3 ms·
Afaik that just runs in serial, like the original example. `await` pauses execution immediately.
by ajkjk 6y ago
Afaik that just runs in serial, like the original example. `await` pauses execution immediately.
- recursive 6y agoYes, but the first pause comes after both requests have been started.
- ajkjk 6y agoAre you sure? It seems incongruous with my mental model, which is that the first `await`, when executed, immediately pauses execution, so the second is only dispatched when the first has resolved.
- recursive 6y agoYes. > the first `await`, when executed, immediately pauses execution Also true, but in my code, the first `await` happens after the second `fetch()` has already begun.
- DangitBobby 6y agoThe second await does not start until the first await resolves the first promise, but that doesn't mean network activity for the second initiated request isn't still happening in the background.
- DangitBobby 6y agoIn all examples provided, unless you want to return them as separate promises, you must await at some point. My understanding is that calling await on a promise does not prevent other Promises from being fulfilled, it just pauses execution of the rest of the code block. For example, if you performed two web requests and then awaited a setTimeout for a few seconds, your two web request promises would likely already be resolved by the time you awaited them. Which would mean that the difference between await fetch await fetch concat and fetch fetch concat await is that the fetch can actually perform asynchronous web activity in the latter example.