Skip to main content
Module

x/async_channels/mod.ts>Sender

Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.
Go to Latest
interface Sender
Re-export
import { type Sender } from "https://deno.land/x/async_channels@v1.0.0-alpha45/mod.ts";

Type Parameters

T

The type of value that can be sent.

Methods

send(val: T, abortCtrl?: AbortController): Promise<void>

Sends a value on the channel, and returns a promise that will be resolved when a the value is received (see Channel.receive), or rejected if a provided AbortController is aborted.

If the channel is closed, then the promise will be rejected with an InvalidTransitionError.

import {Channel, InvalidTransitionError} from "./channel.ts"

const ch = new Channel()
ch.close();
try {
  await ch.send("should fail")
  console.assert(false, "unreachable")
} catch (e) {
  console.assert(e instanceof InvalidTransitionError)
}