- From: Yutaka Hirano <yhirano@google.com>
- Date: Fri, 28 Jun 2013 11:07:57 +0900
- To: www-dom@w3c.org
- Message-ID: <CABihn6HdZKYUu2Ucv8h0VU+F9dYsnSHMtYSaozSmUmSO7oEfAg@mail.gmail.com>
Hi, I am implementing promises and I have a question.
In resolve algorithm, we create promise callbacks for the given resolver
and pass them to a (possibly) user defined function.
A user can call them more than once.
Since a promise callback for |resolver| and |algorithm| runs |resolver|'s
|algorithm| and the |algorithm| doesn't checks |resolver|'s resolved flag,
it seems that the promise can be resolved or rejected multiple times.
Is it correct? I think the check for the resolved flag is needed in at
least:
- promise callback
- 4.4 in resolve algorithm.
Example:
var resolver;
var promise = new Promise(function(r) {resolver = r;});
promise.then(function(result) {
console.log('FULFILLED: result = ' + result);
}, function(result) {
console.log('REJECTED: result = ' + result);
});
var value = {
then: function (resolvePromiseCallback, rejectPromiseCallback) {
// We can resolve the promise, of course.
resolvePromiseCallback(1);
// Can we resolve it again?
resolvePromiseCallback(2);
// Can we reject it after resolving it?
rejectPromiseCallback(3);
// If we throw an exception, will the promise be rejected again?
throw 4;
}
};
resolver.resolve(value);
Received on Friday, 28 June 2013 07:46:39 UTC