Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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)



Ah! The equivalent with await seems much clearer to me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: