README
channels-js
A Pure JS implentation of channels with async/await
Types
* UnBufferedChannel()
* BufferedChannel(Buffersize) // Needs Buffersize in constructor
* BoundlessChannel() // Unlimited Buffersize | never blocks write
Usage
let channels = reqiure("channels-js");
let UnBufferedChannel = new channels.UnBufferedChannel();
async fucntion write(){
await UnBufferedChannel.write(data);
}
async function read(){
let data = await UnBufferedChannel.read();
//Do Something with Data...
}
write();
read();
Alternate Way to read until nothing wants to write
channels-js now supports Async Iterators[ for await (... of ...) ]
let channel = channels.[Any of the 3 Types]();
async function readAllData(){
for await(data of channel){
// Do Something with data ...
}
}
More Examples
let channels = reqiure("channels-js");
let BufferedChannel = new channels.BufferedChannel(10);
async function write(){
while(true){
await BufferedChannel.write(data); // Blocks only after internal Buffer is fulf
}
}
async function read(){
let data = await UnBufferedChannel.read();
//Do Something with Data...
}
write();
read();