S
S
Sergey2020-06-08 15:39:00
JavaScript
Sergey, 2020-06-08 15:39:00

How to understand the inner workings of Promises in Javascript?

Reviewed a lot of materials on JS Promise, incl. questions from here

  • this lesson by Vladilen Minin on Youtube
  • material on MDN
  • More material on JavaScript.ru


It is clear what it is useful for and approximately how to use it.
But I want a deeper, more conscious understanding of how it works under the hood.

Where can I see the clear essence of the implementation? Are there any simple examples of the implementation of Promise "from scratch" in JS, in which you can see all the "magic" that happens - how and what is passed where, returned?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir, 2020-06-08
@paper_castle

In the old days, when promises were not supported by browsers, there was their implementation on Bluebird JS
In addition to the V8 sources, you can look at https://github.com/petkaantonov/bluebird/
Well, for the "outdoor" device https://habr.com/ ru/company/mailru/blog/269465/

2
2CHEVSKII, 2020-06-08
@2chevskii

how it works under the hood

V8 is open source.

T
twoone, 2020-06-08
@twoone

A long time ago, when there was no Promise in javascript yet, I studied the sources of several alternatives available at that time and I can say that it is not so easy for someone who has just recently become acquainted with the concept of asynchrony bet to understand the many constructs necessary for clean code. Links to the best implementations at the moment have already been given to you, but if you want something very simple with comments, then a variant written in haste can be useful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question