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.
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
2.2.6.1
If/when
promise
is fulfilled, respectiveonFulfilled
callbacks must execute in the order of their originating calls tothen
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.