Skip to content

Instantly share code, notes, and snippets.

@davidbarral
Created January 20, 2018 16:11
Show Gist options
  • Save davidbarral/6a7d2a54e26907fc80c8acdb073609d2 to your computer and use it in GitHub Desktop.
Save davidbarral/6a7d2a54e26907fc80c8acdb073609d2 to your computer and use it in GitHub Desktop.
Promisify: adhoc custom promisify
const CUSTOM = Symbol("promisify.custom");
const promisify = fn => {
if (fn[CUSTOM]) {
return fn[CUSTOM];
}
return (...args) => new Promise((resolve, reject) => {
fn(...args, (error, value) => {
if (error) {
reject(error);
} else {
resolve(value);
}
});
});
};
promisify.custom = CUSTOM;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment