Last active
August 29, 2015 14:10
-
-
Save jquense/44315ee5eb506a2aafe6 to your computer and use it in GitHub Desktop.
Promise API conundrum
This file contains 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
// 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