x/async_channels@v1.0.0-rc8

Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.
Latest
scripts/
src/
import * as asyncChannels from "https://deno.land/x/async_channels@v1.0.0-rc8/mod.ts";

Classes

AbortedError

The Error class used when get or send are aborted before completion.

BroadcastChannel
Channel
InvalidTransitionError

The Error class used when an invalid transition is performed.

SendOnClosedError

The Error class used when the send transition is performed on a closed channel.

time.Ticker

A Ticker holds a channel that delivers “ticks” of a clock at intervals.

time.Timer
UnreachableError

Variables

defaultBroadcastSendMode
pipe.otherTopics
time.after

after waits for the duration to elapse and then sends the current time on the returned channel. It is equivalent to (new Timer(d)).c. If efficiency is a concern, use new Timer() instead and call Timer.stop if the timer is no longer needed.

time.tick

tick is a convenience wrapper for new Ticker(d) providing access to the ticking channel only. While tick is useful for clients that have no need to shut down the Ticker, be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks".

time.timeout

timeout creates a channel that will close after duration milliseconds.

Interfaces

BroadcastChannelOptions
ChannelOptions

Extra options for new channels.

ClosedReceiver
pipe.ChannelDuplicateOptions
pipe.ChannelPipeOptions

Options for pipe operations.

SelectOptions

Extra options used for the select function.

Async Channels

Latest Version Test & Release codecov nodejs minimum version License: GPL v3

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 github.com:@Eyal-Shalev/async_channels

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