Skip to content

Iquiji/channels-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 = require("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 = require("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();

About

A Pure JS implentation of channels

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages