Skip to content

Instantly share code, notes, and snippets.

@cdata
Forked from getify/gist:9110935
Last active August 29, 2015 13:56
Show Gist options
  • Save cdata/9117549 to your computer and use it in GitHub Desktop.
Save cdata/9117549 to your computer and use it in GitHub Desktop.

Consistency is in the eye of the beholder..

// Hey, what gives here? This is weird and unexpected.
// Why is the promise factory called synchronously, when
// all the other steps resolve async? For consistency,
// one would expect them all to be async.

var p = new Promise(function(resolve,reject){
   console.log("what");
   resolve();
});

p.then(function(){
   console.log("here?");
});

console.log("happened");

// got: what, happened, here?
// expected: happened, what, here?

Consider the same code using Q:

var d = Q.defer();
var p = d.promise;

console.log("what");
d.resolve();

p.then(function() {
  console.log("here?");
});

console.log("happened");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment