Created
January 20, 2018 16:11
-
-
Save davidbarral/6a7d2a54e26907fc80c8acdb073609d2 to your computer and use it in GitHub Desktop.
Promisify: adhoc custom promisify
This file contains hidden or 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 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