Skip to main content
Module

x/async_channels/mod.ts>Channel

Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.
Go to Latest
class Channel
implements Sender<T>, Receiver<T>, Closer, AsyncIterable<T>
Re-export
import { Channel } from "https://deno.land/x/async_channels@v1.0.0-alpha45/mod.ts";

Constructors

new
Channel(bufferSize?, options?: ChannelOptions)

Constructs a new Channel with an optional buffer.

Type Parameters

T

The type of value held by this channel.

Properties

protected
current: State
protected
optional
currentVal: T
protected
readonly
queue: Queue<T>
protected
stateEventTarget: EventTarget
protected
transitionEventTarget: EventTarget

Methods

protected
debug(...args: unknown[])
protected
error(...args: unknown[])
protected
updateState(t: Transition, val?: T): void
protected
waitForState(...states: State[]): Promise<T | undefined>
filter(
fn: (val: T) => boolean | Promise<boolean>,
bufferSize?,
options?: ChannelPipeOptions | undefined,
): Receiver<T>
flatMap<TOut>(
fn: (val: T) => Iterable<TOut> | AsyncIterable<TOut>,
bufferSize?,
options?: ChannelPipeOptions | undefined,
): Receiver<TOut>
forEach(
fn: (val: T) => void | Promise<void>,
bufferSize?,
options?: ChannelPipeOptions | undefined,
): Receiver<void>
map<TOut>(
fn: (val: T) => TOut | Promise<TOut>,
bufferSize?,
options?: ChannelPipeOptions | undefined,
): Receiver<TOut>
receive(abortCtrl?: AbortController): Promise<[T, true] | [undefined, false]>
reduce(
fn: (prev: T, current: T) => T | Promise<T>,
bufferSize?,
options?: ChannelPipeOptions | undefined,
): Receiver<T>
send(val: T, abortCtrl?: AbortController): Promise<void>
[Symbol.asyncIterator](): AsyncGenerator<T, void, void>

Static Methods

from<T>(
input: Iterable<T> | AsyncIterable<T>,
bufferSize?: number,
options?: ChannelOptions,
): Receiver<T>