javascript - Q promise: are callbacks invoked in the same order as registered? -
i'm using q promise library. code relies on fact callbacks single promise executed in same order registered.
var deferred = q.defer(); var promise = deferred.promise; ['first', 'second', 'third'].foreach(function (position) { promise.then(function () { alert(position); }); }); deferred.resolve();
this produce correct result, don't know if it's part of spec or happy coincidence break down line.
from promises/a+ spec
2.2.6.1
if/when
promise
fulfilled, respectiveonfulfilled
callbacks must execute in order of originating callsthen
.
Comments
Post a Comment