S
S
sergey199408082018-07-18 11:10:11
JavaScript
sergey19940808, 2018-07-18 11:10:11

JS, what's under the hood of the async await construct?

Hello, what happens when we call await function fetchUser().
I believe that this is a wrapper over a generator that suspends the course of an asynchronous function.
But I've also seen that it's just a call to Promise.all([]). So what's going on under the hood?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Flying, 2018-07-18
@sergey19940808

Yes, under the hood there are generators and promises. One way to test this is to transpile your async/await code to ES5 using Babel and see what happens. I made a small gist with a test project, you can see the result there. Babel uses regenerator to implement generators.

S
Sergey Sokolov, 2018-07-18
@sergiks

Detailed answer to the question in English.
async / await is syntactic sugar. Under the hood is a generator and yield .

A
Anton Spirin, 2018-07-18
@rockon404

AsyncFunction source code in V8
Uses generators.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question