Skip to content

Instantly share code, notes, and snippets.

@davidbarral
Last active September 2, 2020 01:31
Show Gist options
  • Save davidbarral/5e8d2f7e1bdd526a9aa0065dc872e538 to your computer and use it in GitHub Desktop.
Save davidbarral/5e8d2f7e1bdd526a9aa0065dc872e538 to your computer and use it in GitHub Desktop.
Callbackify: adhoc callbackify
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