Skip to content

Instantly share code, notes, and snippets.

@jquense
Last active August 29, 2015 14:10
Show Gist options
  • Save jquense/44315ee5eb506a2aafe6 to your computer and use it in GitHub Desktop.
Save jquense/44315ee5eb506a2aafe6 to your computer and use it in GitHub Desktop.
Promise API conundrum
// my thing
Thing = {
addPromise: function(fn){
Promise.resolve(fn.call(this, 'input'))
.then(function(val){
//do wahtever
})
},
addNode: function(fn){
fn.call(this, 'input', done)
function done(val){
//do wahtever
}
}
}
// consumer provides a fn to my Thing
Thing.addNode(function(input, done){
doAsyncWork(input, function(err,val){
done(err, val)
})
})
Thing.addPromise(function(input){
return doAsyncWork(input)
})
Thing.addPromise(function(input){
return input + "sync value"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment