为什么Promise在其中长时间运行时会被阻止

时间:2018-09-20 08:29:16

标签: javascript promise

function main(){
      console.log('A');
      var p = new Promise(function(res, rej) {
        runWhileLoopForNSeconds(20);
        console.log('While loop is done');
        res(1);
      });
      console.log('C');
}
main();
function runWhileLoopForNSeconds(sec){
  let start = Date.now(), now = start;
  while (now - start < (sec*1000)) {
    now = Date.now();
  }
}

Promise阻止整个功能,直到完成为止。它不是异步运行代码

0 个答案:

没有答案