v1.0.0-test4
Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.
Repository
Current version released
3 years ago
Versions
- v1.0.0-rc8Latest
- 1.0.0-rc7
- v1.0.0-rc7
- 0.0.0-test1
- 1.0.0-rc6
- v1.0.0-rc6
- 1.0.0-test6
- v1.0.0-test6
- 1.0.0-test5
- v1.0.0-test5
- 1.0.0-test4
- v1.0.0-test4
- 1.0.0-test3
- v1.0.0-test3
- v1.0.0-test2
- v1.0.0-test1
- 1.0.0-rc5
- 1.0.0-rc4
- v1.0.0-rc5
- v1.0.0-rc4
- 1.0.0-rc3
- v1.0.0-rc3
- 1.0.0-rc2
- v1.0.0-rc2
- refs/heads/test-on-main
- 1.0.0-rc1
- v1.0.0-rc1
- 1.0.0-beta7
- v1.0.0-beta7
- 1.0.0-beta6
- v1.0.0-beta6
- 1.0.0-beta5
- v1.0.0-beta5
- 1.0.0-beta4
- v1.0.0-beta4
- 1.0.0-beta3
- v1.0.0-beta3
- 1.0.0-beta2
- v1.0.0-beta2
- 1.0.0-beta1
- v1.0.0-beta1
- 1.0.0-alpha66
- v1.0.0-alpha66
- 1.0.0-alpha65
- v1.0.0-alpha65
- v1.0.0-alpha64
- 1.0.0-alpha63
- v1.0.0-alpha63
- 1.0.0-alpha62
- v1.0.0-alpha62
- 1.0.0-alpha61
- v1.0.0-alpha61
- 1.0.0-alpha60
- v1.0.0-alpha60
- 1.0.0-alpha59
- v1.0.0-alpha59
- 1.0.0-alpha58
- v1.0.0-alpha58
- 1.0.0-alpha57
- v1.0.0-alpha57
- v1.0.0-alpha56
- 1.0.0-alpha55
- v1.0.0-alpha55
- 1.0.0-alpha54
- v1.0.0-alpha54
- draft-refs/pull/46/merge
- 1.0.0-alpha53
- v1.0.0-alpha53
- v1.0.0-alpha52
- v1.0.0-alpha51
- 1.0.0-alpha50
- v1.0.0-alpha50
- v1.0.0-alpha49
- v1.0.0-alpha48
- 1.0.0-alpha47
- v1.0.0-alpha47
- 1.0.0-alpha46
- v1.0.0-alpha46
- 1.0.0-alpha45
- v1.0.0-alpha45
- 1.0.0-alpha44
- v1.0.0-alpha44
- v1.0.0-alpha43
- v1.0.0-alpha42
- 1.0.0-alpha41
- v1.0.0-alpha41
- 1.0.0-alpha40
- v1.0.0-alpha40
- 1.0.0-alpha39
- v1.0.0-alpha39
- 1.0.0-alpha38
- v1.0.0-alpha38
- v1.0.0-alpha37
- v1.0.0-alpha36
- v1.0.0-alpha35
- v1.0.0-alpha34
- v1.0.0-alpha33
- v1.0.0-alpha32
- 1.0.0-alpha31
- v1.0.0-alpha31
- v1.0.0-alpha30
- 1.0.0-alpha29
- v1.0.0-alpha29
- 1.0.0-alpha28
- v1.0.0-alpha28
- 1.0.0-alpha27
- v1.0.0-alpha27
- 1.0.0-alpha26
- v1.0.0-alpha26
- 1.0.0-alpha25
- v1.0.0-alpha25
- 1.0.0-alpha24
- v1.0.0-alpha24
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.
Setup
NodeJS
Released under both npmjs & github packages:
Install:
npm
npm install @eyalsh/async_channels
yarn
yarn add @eyal-shalev/async_channels
import (ES Modules):
import { Channel } from "@eyalsh/async_channels";
require (CommonJS):
const { Channel } = require("@eyalsh/async_channels");
Deno
The library is available to import from deno.land/x/async_channels
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 or unpkg.com.
import { Channel } from "https://cdn.skypack.dev/@eyalsh/async_channels";
Or you can download compiled library from GitHub:
import { Channel } from "/path/to/async_channels.esm.js";
Note: an IIFE version also exist, if your application doesn’t support ES modules.
<script src="/path/to/async_channels.iife.js"></script>
<script>
const {Channel} = async_channels;
</script>
Examples
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 }); }