v1.0.0-alpha49
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
Inspired by Go
& Clojure
Channels, async_channels
provides channels as an
asynchronous communication method between asynchronous functions.
Installation
Vanilla JS (CDN)
Import the module from one of the CDNs that mirror npmjs.com:
import { Channel } from "https://cdn.skypack.dev/@eyalsh/async_channels";
const ch = new Channel();
// ...
Vanilla JS (Download)
A compiled version exists for every major dependency management system in the
releases section.
Download one of them and import it
import { Channel } from "/path/to/async_channels.esm.js";
const ch = new Channel();
// ...
NPM (ESM)
Released under both npmjs & github packages:
import { Channel } from "@eyalsh/async_channels"; // or "@eyal-shalev/async_channels" for github packages.
const ch = new Channel();
// ...
NPM (CommonJS)
Released under both npmjs & github packages:
const { Channel } = require("@eyalsh/async_channels"); // or "@eyal-shalev/async_channels" for github packages.
const ch = new Channel();
// ...
Deno
import { Channel } from "https://deno.land/x/async_channels/mod.ts";
const ch = new Channel<unknown>();
Example
import { Channel, time } from "https://deno.land/x/async_channels/mod.ts";
function produce(num: number) {
const ch = new Channel(0);
(async () => {
for (let i = 0; i < num; i++) {
await time.timeout(100).receive(); // Do some work...
await ch.send(i);
}
})().catch((err) => console.error(err))
.finally(() => ch.close());
return ch;
}
time.timeout(300).receive().then(() => console.log("boo"));
for await (const product of produce(4)) {
console.log({ product });
}