W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2013

[promises] resolver's resolved flag check on promise callback

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


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.
    // Can we resolve it again?
    // Can we reject it after resolving it?
    // If we throw an exception, will the promise be rejected again?
    throw 4;

Received on Friday, 28 June 2013 07:46:39 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:37:02 UTC