Last active
January 12, 2016 03:39
-
-
Save lsongdev/5941c6bd56526805d5f0 to your computer and use it in GitHub Desktop.
warp callback style function to 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
/** | |
* [promiseify description] | |
* @param {[type]} creator [description] | |
* @return {[type]} [description] | |
*/ | |
module.exports = function promiseify(creator){ | |
return new Promise(function(accept, reject){ | |
creator.call(this, function(err, res){ | |
if(err) return reject(err); | |
accept(res); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment