ES6 Block Promise Page

Given the following test code:

var p = new Promise(function(resolve, reject) {
    for(var i=0;i<10000000;++i)
        for(var y=i;y<10000000;++y)
            z = i + y;
    resolve();
});
p.then(function(){alert("resolved");});

This code should run asynchronously, but it blocks all interaction with the page. Why?

This has been tested in Chrome 44, according to this Promises table should be fully implemented.

Spell here (warning: blocks tab)

+4
source share
2 answers

This code must run asynchronously

Yes and no, it depends on which part of this code you are talking about. The code in your promise maker (the function you pass to new Promise) does not execute asynchronously. From §25.4.3.1 , step 10:

Call (, undefined, "resolvingFunctions. [[Resolve]], resolvingFunctions. [[Reject]]" ).

, new Promise, . ( " Call", EnqueueJob").

then, new Promise. (§25.4.5.3 §25.4.5.3.1.) , , then, , " EnqueueJob".

, :

  • new Promise, .

  • new Promise , p.

  • p.then(...); .

  • JavaScript .

  • , , .

+7

!=

JavaScript . Promises . .

, JavaScript, , f p.then(f) , , .. , , , , ( ).

JS , , , .

, , , , , . JavaScript, -, , , , . , JavaScript ( ).

Promises

Promises , , , , ( , ).

Promises ( Promise.all Promise.race), ( ) .

+2

Source: https://habr.com/ru/post/1589384/


All Articles