Skip to content

Instantly share code, notes, and snippets.

@Spaxe
Created December 16, 2015 22:21
Show Gist options
  • Save Spaxe/132dac12c323dc016fad to your computer and use it in GitHub Desktop.
Save Spaxe/132dac12c323dc016fad to your computer and use it in GitHub Desktop.
Promise wrapper - turns any async function with callback into a ES6 Promise
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