1.0.0 • Published 6 years ago
chan-async v1.0.0
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