A simple helper function to use bind
with generator functions.
It works like lodash bind
function, or the
built-in bind
, but takes and returns a generator function
instead of a normal one.
$ npm install bind-gen
var co = require('co');
var bindGen = require('bind-gen');
var myGenerator = function *(myArg, myOtherArg) {
console.log(this.v);
console.log(myArg);
console.log(myOtherArg);
};
var context = {v: 'the-context'};
var boundGenerator = bindGen(myGenerator, context, 'arg');
co(boundGenerator('other arg'));
// will print:
// the-context
// arg
// other arg