channel-light
go
-language like Channel. CSP-style channel.
PREPARE
$ npm install channel-light --save
USAGE
Channel = require('channel-light')
prepare Channel.
var Channel = ;
channel = new Channel(callback,...)
make new channel.
var channel = ;
make new channel with 3 callbacks.
var channel = ;
callback(err, val)
callback format. this
is channel itself.
{ // use `this` as channel. // you can `throw` with error.}
channel = channel(callback,...)
add callback into channel for receive values.
;;
channel = channel(err, val)
send values into channel.
;;;
normalize callback arguments.
; // -> callback(null, 'val1'); // -> callback(null, ['elem1', 'elem2']); // -> callback(null, 0); // -> callback(null, false); // -> callback(null, true)
QUICK EXAMPLE
void { 'use strict'; // Channel var Channel = ; // Channel() creates a new channel. var chan = ; // call channel with callback arguments. // channel returns itself, can be chained. // `this` is channel when callback. ; };
void { 'use strict'; // Channel var Channel = ; // you don't need variable that keep a channel. ; };
EXAMPLE USING aa (async-await)
$ npm install aa channel-light
communicate with 2 threads.
var Channel = ; var aa = ; ; { return { ; }; }
LICENSE
MIT