Created
June 14, 2016 18:44
-
-
Save ilearnio/ca2c3bc9545c3ba01b0a2d07357369f6 to your computer and use it in GitHub Desktop.
Converst function into yieldable (JavaScript)
This file contains 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
/** | |
* Converst function into yieldable | |
* @param {Function} | |
* @return {Function} yieldable callback | |
*/ | |
function yieldable (func) { | |
return function () { | |
let args = [].slice.call(arguments); | |
let ctx = this; | |
return function (done) { | |
args.push(function (err, result) { | |
done(err, result); | |
}); | |
func.apply(ctx, args); | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment