5 ms·
If it makes it easier to reason about, it's equivalent to: // The Promise resolves when the server starts responding const response = await fetch(…);
by bfred_it 9y ago
If it makes it easier to reason about, it's equivalent to:
// The Promise resolves when the server starts responding
const response = await fetch(…);
// The Promise resolves when both the transfer and the JSON parsing ended
const body = await response.json();
So, yes, `response` is only used once and then discarded.
`fetch()` may fool you into thinking that it resolves when the request is complete, but it's always a 2-step operation (unless you start implementing a streaming interface, then it's more than 2 steps)
- TekMol 9y agoAh! The equivalent with await seems much clearer to me.