且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Q承诺的串行执行

更新时间:2023-02-17 12:20:35

这有效:

doWork('task one')
  .then(function() {
    return doWork('task two')
  })
  .then(function() {
    console.log('all done'); 
  });

这是有道理的 - 只需直接调用 doWork 然后()将立即触发超时,而不是让Q有机会等到任务1 完成。

That makes sense - just calling doWork directly in then() will fire off the timeout immediately, instead of giving Q a chance to wait until task one is complete.