You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While using the lib I found that at some point people will have to use node callback and event emitter based lib with channels.
Here is two utilities functions I ended up with :
/** * Create a channel from an async node function * Passed function must accept a node callback as last args * * @param {function} f * @return {Channel} */functionfromNodeCallback(f){varargs=2<=arguments.length ? Array.prototype.slice.call(arguments,1) : [];varchan=csp.chan();args.push(function(err,value){csp.putAsync(chan,err ? err : value,function(){chan.close();});});f.apply(this,args);returnchan;}/** * Create a channel from an event emitter object * * @param {function} eventEmitter * @param {string} eventName * @param {Channel} [chan] * * @return {Channel} */functionfromEvent(eventEmitter,eventName,chan){chan=chan||csp.chan();eventEmitter.on(eventName,function(data){csp.putAsync(chan,data);});returnchan;}
The text was updated successfully, but these errors were encountered:
While using the lib I found that at some point people will have to use node callback and event emitter based lib with channels.
Here is two utilities functions I ended up with :
The text was updated successfully, but these errors were encountered: