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)
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:
new Promise
Call (, undefined, "resolvingFunctions. [[Resolve]], resolvingFunctions. [[Reject]]" ).
, new Promise, . ( " Call", EnqueueJob").
then, new Promise. (§25.4.5.3 §25.4.5.3.1.) , , then, , " EnqueueJob".
then
, :
new Promise, .
new Promise , p.
p
p.then(...); .
p.then(...)
JavaScript .
, , .
JavaScript . Promises . .
, JavaScript, , f p.then(f) , , .. , , , , ( ).
f
p.then(f)
JS , , , .
, , , , , . JavaScript, -, , , , . , JavaScript ( ).
Promises , , , , ( , ).
Promises ( Promise.all Promise.race), ( ) .
Promise.all
Promise.race
Source: https://habr.com/ru/post/1589384/More articles:Visual Studio - debugging a huge list of objects - c #HTML5 Date and Time Format - html5Correct Positioning of Keyboard Shortcuts ToolStripMenu - vb.netJavadoc related to split package - java-8JS Carousel Pure Error - javascriptLaunching a monomorphic Consumer inside a pipe - haskellHow to find the string that generates Pandas SettingWithCopyWarning? - pythonHow to synchronize execution control with a dataset that loads in a dialog box in Visual C ++ - c ++Как я могу определить и получить доступ к классам под pandas? - pythonСоглашение об именах Python: указывает, изменяет ли функция аргументы - pythonAll Articles