Created
December 16, 2015 22:21
-
-
Save Spaxe/132dac12c323dc016fad to your computer and use it in GitHub Desktop.
Promise wrapper - turns any async function with callback into a ES6 Promise
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
let promise = ( func, ...args ) => { | |
return new Promise( ( resolve, reject ) => { | |
let callback = ( error, data ) => { | |
if (error) reject(error); | |
else resolve(data); | |
}; | |
args.push(callback); | |
func.apply(func, args); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment