Skip to content

Instantly share code, notes, and snippets.

@cblanc
Last active November 29, 2018 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cblanc/ba7a50a37126afbb147a4df432eb8b12 to your computer and use it in GitHub Desktop.
Save cblanc/ba7a50a37126afbb147a4df432eb8b12 to your computer and use it in GitHub Desktop.
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