Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
channel-light
Advanced tools
go
-language like Channel. CSP-style channel.
$ npm install channel-light --save
prepare Channel.
var Channel = require('channel-light');
make new channel.
var channel = Channel();
make new channel with 3 callbacks.
var channel = Channel(
function (err, val) {},
function (err, val) {},
function (err, val) {}
);
callback format. this
is channel itself.
function callback(err, val) {
// use `this` as channel.
// you can `throw` with error.
}
add callback into channel for receive values.
channel(function (err, val) {});
channel(
function (err, val) {},
function (err, val) {}
);
send values into channel.
channel(null, 'val1');
channel(null, 'val2');
channel(new Error('error'));
normalize callback arguments.
channel('val1'); // -> callback(null, 'val1')
channel('elem1', 'elem2'); // -> callback(null, ['elem1', 'elem2'])
channel(0); // -> callback(null, 0)
channel(false); // -> callback(null, false)
channel(true); // -> callback(null, true)
void function () {
'use strict';
// Channel
var Channel = require('channel-light');
// Channel() creates a new channel.
var chan = Channel();
// call channel with callback arguments.
// channel returns itself, can be chained.
// `this` is channel when callback.
chan(function () {
console.log('start!'); // start!
setTimeout(this, 500, 'a');
}, function (err, val) {
// process a.
console.log('a? ' + val);
setTimeout(this, 500, 'b');
}, function (err, val) {
// process b.
console.log('b? ' + val);
setTimeout(this, 500, 'c');
}, function (err, val) {
// process c.
console.log('c? ' + val);
console.log('end');
})();
}();
void function () {
'use strict';
// Channel
var Channel = require('channel-light');
// you don't need variable that keep a channel.
Channel(function () {
setTimeout(this, 3000, 'a2');
}, function (err, val) {
console.log('a2? ' + val);
setTimeout(this, 500, 'b2');
}, function (err, val) {
console.log('b2? ' + val);
setTimeout(this, 500, 'c2');
}, function (err, val) {
console.log('c2? ' + val);
var next = this;
setTimeout(function () {
next('d2');
}, 500);
}, function (err, val) {
console.log('d2? ' + val);
// parallel processing. which one is first?
var next = this, arr = [], chan2 = Channel(
function (err, val) { console.log('e2 1st? ' + val); arr.push(val); },
function (err, val) { console.log('e2 2nd? ' + val); arr.push(val); next(arr); });
setTimeout(chan2, 300, 'e2X');
setTimeout(chan2, 200, 'e2Y');
}, function (err, arr) {
console.log('e2 arr: ' + arr.join(', '));
// you can get an array for multiple values.
this('f21', 'f22', 'f23');
}, function (err, val) {
console.log('f2 values: ' + val.join(', '));
// when you use Promise.
this(new Promise(function (res, rej) {
setTimeout(res, 500, 'g2');
}));
}, function (err, val) {
console.log('g2? ' + val);
console.log('end');
})();
}();
$ npm install aa channel-light
communicate with 2 threads.
var Channel = require('channel-light');
var aa = require('aa');
aa(function *() {
yield wait(100, 'a');
var chan1 = Channel(), chan2 = Channel();
yield [
function *() {
yield wait(100);
chan2(null, 'request message'); // send message
yield chan1; // receive message
yield wait(100);
},
function *() {
yield wait(200);
yield chan2; // receive message
yield wait(100);
chan1(null, 'response message'); // send message
yield wait(100);
}
];
});
function wait(ms, val) {
return function (cb) { setTimeout(cb, ms, null, val); };
}
MIT
FAQs
light version of Channel.
The npm package channel-light receives a total of 0 weekly downloads. As such, channel-light popularity was classified as not popular.
We found that channel-light demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.