Q promise: are callbacks invoked in the same order as registered?

别等时光非礼了梦想. 提交于 2019-12-18 19:14:09

问题


I'm using the Q promise library. My code relies on the fact that the callbacks for a single promise are executed in the same order as they were registered.

http://jsfiddle.net/HgYtK/1/

var deferred = Q.defer();
var promise = deferred.promise;

['first', 'second', 'third'].forEach(function (position) {
  promise.then(function () {
    alert(position);
  });
});

deferred.resolve();

This does produce the correct result, but I don't know if it's part of the spec or a happy coincidence that could break down the line.


回答1:


From the Promises/A+ Spec

2.2.6.1

If/when promise is fulfilled, respective onFulfilled callbacks must execute in the order of their originating calls to then.



来源:https://stackoverflow.com/questions/16550356/q-promise-are-callbacks-invoked-in-the-same-order-as-registered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!