https://github.com/eyal-shalev/async_channels
Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.
https://github.com/eyal-shalev/async_channels
async channel channels deno javascript typescript
Last synced: 11 months ago
JSON representation
Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.
- Host: GitHub
- URL: https://github.com/eyal-shalev/async_channels
- Owner: Eyal-Shalev
- License: gpl-3.0
- Created: 2021-08-31T19:53:35.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-09-03T21:35:11.000Z (almost 2 years ago)
- Last Synced: 2025-07-05T14:19:25.313Z (12 months ago)
- Topics: async, channel, channels, deno, javascript, typescript
- Language: TypeScript
- Homepage: https://eyal-shalev.github.io/async_channels/
- Size: 407 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Async Channels
[](https://github.com/Eyal-Shalev/async_channels)
[](https://github.com/Eyal-Shalev/async_channels/actions/workflows/test.yml)
[](https://codecov.io/gh/Eyal-Shalev/async_channels)
[](https://www.npmjs.com/package/@eyalsh/async_channels)
[](https://www.gnu.org/licenses/gpl-3.0)
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.
## Setup
### NodeJS
Released under both npmjs & github packages:
[](https://www.npmjs.com/package/@eyalsh/async_channels)
[](https://github.com/Eyal-Shalev/async_channels/packages/983326)
**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");
```
### Deno
The library is available to import from
[deno.land/x/async_channels](://deno.land/x/async_channels)
```ts
import { Channel } from "https://deno.land/x/async_channels/mod.ts";
```
### Browser - CDN / Download
You can import the library from any CDN that mirrors _npmjs.com_, such as
[skypack.dev](://skypack.dev/view/@eyalsh/async_channels) or
[unpkg.com](https://unpkg.com/@eyalsh/async_channels/dist/async_channels.esm.js).
```js
import { Channel } from "https://cdn.skypack.dev/@eyalsh/async_channels";
```
Or you can download compiled library from GitHub:
- [Latest Release](://github.com/Eyal-Shalev/async_channels/releases/latest)
- [All Releases](://github.com/Eyal-Shalev/async_channels/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
const {Channel} = async_channels;
```
## Examples
- [middleware (ping-pong)](/examples/middleware)
- [pipeline (even or odd)](/examples/even-or-odd-pipeline)
- [pipeline (lorem-ipsum)](/examples/lorem-ipsum-pipeline)
- [Message Queue](/examples/message-queue)
- [static site (todos app)](/examples/todos-static)
- ```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 });
}
```