ChannelClosedError

import { ChannelClosedError } from "jsr:@ende/async";

class

class ChannelClosedError extends Error

Error thrown when operating on a closed channel. When thrown from Channel.send, the value property carries the unsent value for recovery.

Example: Usage

import { Channel, ChannelClosedError } from "@ende/async/channel";
import { assertInstanceOf } from "@ende/assert";

const ch = new Channel<number>();
ch.close();
try {
  await ch.send(42);
} catch (e) {
  assertInstanceOf(e, ChannelClosedError);
}

Constructors

constructor

new ChannelClosedError(message: string, ...rest: [unknown] | [])

Constructs a new ChannelClosedError instance.

message: string

The error message.

...rest: [unknown] | []

If provided, the first element is attached as the non-writable ChannelClosedError.value property.

Properties

value

readonly value?: unknown

The unsent value, present only when the error originates from a send operation.

Example: Usage

import { Channel, ChannelClosedError } from "@ende/async/channel";
import { assertEquals, assertInstanceOf } from "@ende/assert";

const ch = new Channel<number>();
ch.close();
try {
  await ch.send(42);
} catch (e) {
  assertInstanceOf(e, ChannelClosedError);
  assertEquals(e.value, 42);
}

Source