channels-js

0.4.1 • Public • Published

channels-js

A Pure JS implentation of channels with async/await

Build Status npm npm bundle size NPM

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();

Package Sidebar

Install

npm i channels-js

Weekly Downloads

0

Version

0.4.1

License

MIT

Unpacked Size

9.5 kB

Total Files

6

Last publish

Collaborators

  • iquiji