Skip to content

Instantly share code, notes, and snippets.

@cblanc
Last active Nov 29, 2018
Embed
What would you like to do?
const callbackifyPromiseWithTimeout = function(promise, callback) {
if (callback) {
// Ensure callback is called outside of promise stack.
return promise.then(function(res) {
setTimeout(function() { callback(null, res) }, 0);
}, function(err) {
setTimeout(function() { callback(err, null); }, 0);
});
}
return promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment