1.0.0 • Published 6 years ago

chan-async v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

chan-async

A wrapper for chan to support promises.

Installation

$ npm install chan-async

Usage

First import chan-async

const makeChan = require('chan-async');

Create a channel

const ch = makeChan((val) => {
    return new Promise((resolve) => {
        console.log(`Read value: ${val}`);
        setTimeout(() => resolve(val * 2), 500);
    });
});

Write to the channel

ch(42) // Returns a promise
    .then((res) => console.log(`Result: ${res}`))
    .catch((err) => console.error(err));
1.0.0

6 years ago