chan-async

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i chan-async

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

5.81 kB

Total Files

6

Last publish

Collaborators

  • rcpooley