Package detail

sync-channel

snetz17.2kBSD0.0.6

synchronous communication channel

concurrent, channel, async

readme

# SyncChannel

A SyncChannel is an abortable readable/writable communication channel. Communication is synchronous, i.e. the callback of a write gets called only when it's value has been read. Reading/writing from/to a SyncChannel can be aborted by calling the abort function returned by the read/write methods.

$ npm install sync-channel

Examples

read/write

var SyncChannel = require('sync-channel');

var channel = new SyncChannel();

channel.read(function(value) {
    console.log('value read', value);
});

channel.write(123, function() {
    console.log('value written');
});

Aborting a read/write operation

var SyncChannel = require('sync-channel');

var channel = new SyncChannel();

var abortRead = channel.read(function(value) {
    console.log('value read', value);
});

setTimeout(function() {
    abortRead();
    console.log('you are so slow!');
}, 500);

setTimeout(function() {
    channel.write(123, function() {
        console.log('value written');
    });
}, 1000);