ChannelClosedError
import { ChannelClosedError } from "jsr:@ende/async";class
class ChannelClosedError extends ErrorError 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: stringThe error message.
...rest: [unknown] | []If provided, the first element is attached as the non-writable
ChannelClosedError.valueproperty.
Properties
value
readonly value?: unknownThe 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);
}