Created
June 27, 2019 11:54
-
-
Save Warrenn/3267f3f43bbcf5255217960a528c23a7 to your computer and use it in GitHub Desktop.
make a node function call with a callback awaitable
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
function awaitable(fn) { | |
return new Promise((resolve, reject) => { | |
let callback = (err, data) => { | |
if (err) { | |
reject(err); | |
return; | |
} | |
resolve(data); | |
}; | |
var newArgs = Array.prototype.slice.call(arguments, 1); | |
newArgs.push(callback); | |
fn.apply(this, newArgs); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment