cjs
v0.0.11
Published
Concurrent Javascript
Downloads
30,089
Readme
Concurrent Javascript
This is preliminary documentation. Full docs are coming soon.
$ npm install cjs
Examples
read/write
var cjs = require('cjs');
var channel = cjs.newChannel();
channel.read(function(value) {
console.log('value read', value);
});
channel.write(123, function() {
console.log('value written');
});
forever
var cjs = require('cjs');
var channel = cjs.newChannel();
(function loop() {
channel.read(function(value) {
console.log('value read', value);
loop();
});
}());
(function loop() {
channel.write(123, function() {
console.log('value written');
loop();
});
}());
readEvent/writeEvent
var cjs = require('cjs');
var channel1 = cjs.newChannel();
var channel2 = cjs.newChannel();
cjs.select([
channel1.readEvent(),
channel2.readEvent()
], function(error, value) {
console.log('value read on either channel1 or channel2', value);
});
channel1.write(1, function() {
console.log('1 written');
});
channel2.write(2, function() {
console.log('2 written');
});