tildeio / rsvp.js

A lightweight library that provides tools for organizing asynchronous code
MIT License
3.61k stars 264 forks source link

Promise state changed after notification #51

Closed salper closed 11 years ago

salper commented 11 years ago

In the RSVP code, the promise flags are updated after the trigger :

function resolve(promise, value) {
  config.async(function() {
    promise.trigger('promise:resolved', { detail: value });
    promise.isResolved = true;
    promise.resolvedValue = value;
  });
}

function reject(promise, value) {
  config.async(function() {
    promise.trigger('promise:failed', { detail: value });
    promise.isRejected = true;
    promise.rejectedValue = value;
  });

Thus, in the following code :

var a = new Promise();
a.then(function () {
  a.then(function () {
    console.log('resolved');
  });
});

'resolved' will never printed

wagenet commented 11 years ago

I've seen this problem in a live Ember app. Working on a fix now.

domenic commented 11 years ago

There is a test for this in promises-aplus-tests 1.2.0.

domenic commented 11 years ago

In particular see https://github.com/promises-aplus/promises-tests/issues/17

wagenet commented 11 years ago

@domenic, Ah, looks like we need to update our tests.