Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derived Promises don't propagate reject correctly #557

Open
heymatthew opened this issue Jul 20, 2014 · 1 comment
Open

Derived Promises don't propagate reject correctly #557

heymatthew opened this issue Jul 20, 2014 · 1 comment

Comments

@heymatthew
Copy link

If you

  1. create a deferred object
  2. and derive a promise P2 from it's internal promise P1
  3. and P2 is rejected
  4. then a chain P1.then(P2).then... will not cascade the P2 reject. Instead this will behave like P2 was resolved.

Given the following sample snippet

q = require('q');

var deferredA = q.defer();
var promiseA = deferredA.promise;

var derivedPromiseA = promiseA.then(function() {
  var equation = 1+1;
  throw 'fuuuuuuuuuuuuuu';
});

promiseA
  .then( derivedPromiseA )
  .then(function onSuccess() {
    console.log("Unexpected :(");
  })
  .fail(function onFail() {
    console.log("Expected state");
  })
;

deferredA.resolve('go');

It prints "Unexpected :("

Conversely, if you run

derivedPromiseA
  .then(function onSuccess() {
    console.log("Unexpected :(");
  })
  .fail(function onFail() {
    console.log("Expected state");
  })
;

This prints "Expected State"

The use case for having a longer chain is that you can get explicit dependency declaration despite the redundancy. This becomes more obvious if you have branching dependency chains.


Detail:

  • Node v0.10.29
  • Q v1.0.1
@domenic
Copy link
Collaborator

domenic commented Jul 21, 2014

.then takes functions, not promises


From: Matthewmailto:notifications@github.com
Sent: ý2014-ý07-ý20 19:49
To: kriskowal/qmailto:q@noreply.github.com
Subject: [q] Derived Promises don't propagate reject correctly (#557)

Givent the following snippet

q = require('q');

var deferredA = q.defer();
var promiseA = deferredA.promise;

var derivedPromiseA = promiseA.then(function() {
var equation = 1+1;
throw 'fuuuuuuuuuuuuuu';
});

promiseA
.then( derivedPromiseA )
.then(function onSuccess() {
console.log("Unexpected :(");
})
.fail(function onFail() {
console.log("Expected state");
})
;

deferredA.resolve('go');

What actually happens is it prints "Unexpected :("

Conversely, if you run

derivedPromiseA
.then(function onSuccess() {
console.log("Unexpected :(");
})
.fail(function onFail() {
console.log("Expected state");
})
;

This prints "Expected State"

The use case for having a longer chain is that you can get explicit dependency declaration despite the redundancy.


Detail:

  • Node v0.10.29
  • Q v1.0.1


Reply to this email directly or view it on GitHubhttps://github.com//issues/557.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants