import { type Sender } from "https://deno.land/x/async_channels@v1.0.0-alpha45/mod.ts";
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)
}