- From: Yutaka Hirano <yhirano@chromium.org>
 - Date: Thu, 27 Jun 2013 10:51:03 +0900
 - To: www-dom@w3c.org
 - Message-ID: <CABihn6E2G0b3zJ9BpatYSGNv4fgtfQ5f_XVDeNg90DC_9cRF6A@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:
 - 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