Skip to main content
Module

x/async_channels/mod.ts>Channel#send

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

Sends a value on the channel, and returns a promise that will be resolved when a the value is received (see Channel.get), 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)
}

Parameters

val: T

The value to pass to the channel.

optional
abortCtrl: AbortController

Returns

Promise<void>

will be resolved when message was passed, or rejected if abortCtrl was aborted or the channel is closed.