daniel
daniel

Reputation: 334

How does Promises work when JavaScript is single threaded?

How does JavaScript execute Promises async when JS is single threaded? I know how to use Promises, but it is still unclear to me how it works behind the scene.

Upvotes: 3

Views: 842

Answers (1)

SeanCannon
SeanCannon

Reputation: 77956

Promises are just a callback queue assigned to a lookup. Once you resolve the promise, it iterates over all callbacks which have been assigned via then or done.

Upvotes: 2

Related Questions