3 ms·
I don't understand your code. the .json() should be inside the parentheses because you cannot await something that has already been converted from a Promise to
by tigershark 10y ago
I don't understand your code.
the .json() should be inside the parentheses because you cannot await something that has already been converted from a Promise to a real value.
And even in that case that code will be exactly equivalent to the synchronous code because you are awaiting in place the result of the Promise.
So, given my very limited knowledge of javascript, I think that probably you can write it moving the .json() inside, but I don't see why you would ever want to do it if you can have the same result without the await boilerplate...
EDIT: got it, you want to do it inside an aync function with some other code after the await, then I think it makes sense in that case.
- deleted 10y ago[deleted]
- neoeldex 10y agofetch() returns a promise, which is unwrapped using await. fetch's promise contains a response object, which has a json method, which returns a promise. const responsePromise = fetch(https://api.github.com/orgs/facebook'); const response = await responsePromise; const jsonPromise = response.json(); const json = await jsonPromise;