Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.
npm install @eyalsh/async_channels




Channels are queue-like objects _(First In First Out)_ that their enqueue
(send) and dequeue (get) functions are asynchronous (async). By passing them
between asynchronous functions we can synchronize operations between said
functions.
Released under both npmjs & github packages:


Install:
npm
``shell`
npm install @eyalsh/async_channels
yarn
`shell`
yarn add @eyal-shalev/async_channels
import (ES Modules):
`js`
import { Channel } from "@eyalsh/async_channels";
require (CommonJS):
`js`
const { Channel } = require("@eyalsh/async_channels");
The library is available to import from
deno.land/x/async_channels
`ts`
import { Channel } from "https://deno.land/x/async_channels/mod.ts";
You can import the library from any CDN that mirrors _npmjs.com_, such as
skypack.dev or
unpkg.com.
`js`
import { Channel } from "https://cdn.skypack.dev/@eyalsh/async_channels";
Or you can download compiled library from GitHub:
- Latest Release
- All Releases
`js`
import { Channel } from "/path/to/async_channels.esm.js";
_Note: an IIFE version also exist, if your application doesn't support ES
modules._
`html`
- `ts
import { Channel, time } from "https://deno.land/x/async_channels/mod.ts";
function produce(num: number) {
return Channel.from((async function* () {
for (let i = 0; i < num; i++) {
await time.timeout(100).get(); // Do some work...
yield i;
}
})());
}
time.timeout(300).get().then(() => console.log("boo"));
for await (const product of produce(4)) {
console.log({ product });
}
``