Skip to content

Instantly share code, notes, and snippets.

@ilearnio
Created June 14, 2016 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilearnio/ca2c3bc9545c3ba01b0a2d07357369f6 to your computer and use it in GitHub Desktop.
Save ilearnio/ca2c3bc9545c3ba01b0a2d07357369f6 to your computer and use it in GitHub Desktop.
Converst function into yieldable (JavaScript)
/**
* 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