1.0.0-alpha26 • Published 3 years ago

@eyalsh/async-channels v1.0.0-alpha26

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
3 years ago

Async Channels

Test

Inspired by Go & Clojure Channels, async-channels provides channels as an asynchronous communication method between asynchronous functions.

Example

import { Channel } from "https://deno.land/x/async-channels/mod.ts";

const sleep = (duration: number) =>
  new Promise<void>((res) => {
    setTimeout(() => res(), duration);
  });

function produce(num: number) {
  const ch = new Channel(0);
  (async () => {
    for (let i = 0; i < num; i++) {
      await sleep(500); // Do some work...
      await ch.add(i++);
    }
    ch.close();
  })();

  return ch;
}

sleep(200).then(() => console.log("boo"));

for await (let product of produce(5)) {
  console.log({ product });
}
1.0.0-alpha26

3 years ago

1.0.0-alpha25

3 years ago

1.0.0-alpha24

3 years ago

1.0.0-alpha23

3 years ago

1.0.0-alpha22

3 years ago

1.0.0-alpha21

3 years ago

1.0.0-alpha18

3 years ago