# @eyalsh/async_channels

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

Latest version **1.0.0-rc8** (published 2022-05-18) · GPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @eyalsh/async_channels
pnpm add @eyalsh/async_channels
yarn add @eyalsh/async_channels
bun add @eyalsh/async_channels
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc8 |
| Published | 2022-05-18 |
| First published | 2021-09-10 |
| Weekly downloads | 0 |
| License | GPL-3.0-or-later |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 184.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Eyal Shalev |
| Maintainers | eyalsh |
| Keywords | async, channel, channels, await |

## Links

- npm: https://www.npmjs.com/package/@eyalsh/async_channels
- Repository: https://github.com/Eyal-Shalev/async_channels
- Issues: https://github.com/Eyal-Shalev/async_channels/issues
- npm.io page: https://npm.io/package/@eyalsh/async_channels

## Dependencies (1)

- [@deno/shim-timers](https://npm.io/package/@deno/shim-timers.md) ~0.1.0

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.0.0-rc8 (latest) — 2022-05-18
- 1.0.0-rc7 — 2022-05-18
- 0.0.0-test1 — 2022-05-18
- 1.0.0-rc6 — 2022-05-17
- 1.0.0-test6 — 2022-05-17
- 1.0.0-rc5 — 2022-05-16
- 1.0.0-rc3 — 2021-10-09
- 1.0.0-rc2 — 2021-10-08
- 1.0.0-rc1 — 2021-10-06
- 1.0.0-beta7 — 2021-10-03
- 1.0.0-beta6 — 2021-10-03
- 1.0.0-beta5 — 2021-10-03
- 1.0.0-beta4 — 2021-09-27
- 1.0.0-beta3 — 2021-09-27
- 1.0.0-beta2 — 2021-09-27
- … 26 more at https://npm.io/package/@eyalsh/async_channels/versions

## README

# Async Channels

[![Latest Version](https://img.shields.io/github/v/release/eyal-shalev/async_channels?sort=semver&label=Version)](https://github.com/Eyal-Shalev/async_channels)
[![Test & Release](https://github.com/Eyal-Shalev/async_channels/actions/workflows/test-and-release.yml/badge.svg)](https://github.com/Eyal-Shalev/async_channels/actions/workflows/test-and-release.yml)
[![codecov](https://codecov.io/gh/Eyal-Shalev/async_channels/branch/main/graph/badge.svg?token=9EWOZTN2BP)](https://codecov.io/gh/Eyal-Shalev/async_channels)
[![nodejs minimum version](https://img.shields.io/node/v/@eyalsh/async_channels)](https://www.npmjs.com/package/@eyalsh/async_channels)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](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:

[![npmjs.com:@eyalsh/async_channels](https://img.shields.io/badge/npmjs.com-%40eyalsh%2Fasync__channels-%23cc0000)](https://www.npmjs.com/package/@eyalsh/async_channels)
[![github.com:@Eyal-Shalev/async_channels](https://img.shields.io/badge/github.com-%40eyal--shalev%2Fasync__channels-%233399db)](https://github.com/Eyal-Shalev/async_channels/packages/983326)

**Install:**

<details open markdown="block">
<summary>npm</summary>

```shell
npm install @eyalsh/async_channels
```

</details>

<details markdown="block">
<summary>yarn</summary>

```shell
yarn add @eyal-shalev/async_channels
```

</details>

**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
<script src="/path/to/async_channels.iife.js"></script>
<script>
  const {Channel} = async_channels;
</script>
```

## 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 });
  }
  ```

---
_Source: https://npm.io/package/@eyalsh/async_channels · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
