Last active
September 3, 2017 06:13
-
-
Save cantremember/ae0257fe869664dc0cb7 to your computer and use it in GitHub Desktop.
Promise: Deferred vs. new Promise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fooAndBarInParallel() { | |
// boiler-plate. meh | |
var constructed = new Promise(function(resolve, reject) { | |
emitter.once('foo', function(food) { | |
resolve(food); | |
}); | |
}); | |
// such clean. so code | |
var deferred = Promise.deferred(); | |
emitter.once('bar', function(barred) { | |
deferred.resolve(barred); | |
}); | |
return Promise.all([ | |
constructed, | |
deferred.promise, | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment