Last active
September 2, 2020 01:31
-
-
Save davidbarral/5e8d2f7e1bdd526a9aa0065dc872e538 to your computer and use it in GitHub Desktop.
Callbackify: adhoc callbackify
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
const callbackify = fn => (...args) => { | |
const callback = args[args.length - 1]; | |
const fnArgs = args.slice(0, -1); | |
fn(...fnArgs) | |
.then(value => { | |
callback(undefined, value); | |
}) | |
.catch(error => { | |
callback(error); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment