Channel class
Promise based multi producer single consumer channel
-
buffered message queue
-
send/receivebasic message passing -
pipepiping to other channels (or usepipe.to()) -
streamES6 async iterator api -
freezetemporarily block all consumers, useful if your target has limited rate of consumption like Node.js net.Socket
Signature:
export declare class Channel<T> implements PipeSource<T>, PipeTarget<T>
Implements: PipeSource<T>, PipeTarget<T>
Constructors
| Constructor | Modifiers | Description |
|---|---|---|
| (constructor)(capacity) | create a new channel with specified capacity |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
| capacity | number | Get the number of maximum items in queue | |
| ChannelFullError | static | typeof ChannelFullError |
class ChannelFullError extends Error
static | typeof ClosedChannelError |
class ClosedChannelError extends Error
Methods
| Method | Modifiers | Description |
|---|---|---|
| close() | close the channel, future send will throw a Channel.ClosedChannelError | |
| pause() | stop Channel.stream() / Channel.pipe() / Channel.receive() new items until Channel.resume() is called items sending to the channel will be queued despite pipe enabled | |
| pipe(target, options) | pipe channel output to target there is only one target at the same time, use | |
| receive() | retrieve a value from channel. will never resolve if Channel.pipe() or is enabled; will race with Channel.stream() | |
| resume() | resume the channel so Channel.stream() / Channel.pipe() / Channel.receive() can continue to handle new messages | |
| send(value) | send a value to channel. if the channel has reached its capacity, then call to | |
| sendAsync(value) | send a promise to channel, after the promise is resolved, send its fullfilled value | |
| stream() | get a stream to read from the channel, internally uses Channel.receive() | |
| tryReceive() | try receive one message | |
| trySend(value) | try to send a value synchronosly | |
| unpipe() | unlink output with target, future input will be stored in channel's internal buffer |