[英]Q promise: are callbacks invoked in the same order as registered?
I'm using the Q promise library. 我正在使用Q promise库。 My code relies on the fact that the callbacks for a single promise are executed in the same order as they were registered.
我的代码依赖于单个promise的回调按照它们注册的顺序执行的事实。
http://jsfiddle.net/HgYtK/1/ 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. 这确实产生了正确的结果,但我不知道它是否是规范的一部分或者是一个可以打破界限的幸福巧合。
From the Promises/A+ Spec 来自Promises / A + Spec
2.2.6.1
2.2.6.1
If/when
promise
is fulfilled, respectiveonFulfilled
callbacks must execute in the order of their originating calls tothen
.如果/当
promise
被兑现,各onFulfilled
回调必须在其发起的顺序执行调用then
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.