Skip to main content

interface Channel.Constructors

Defines the static Channel API.

Properties

Error

The types of possible Channel errors.

Definition

get Error(): typeof ChannelError;

select

Resolves, from the given channel array, to the channel value that is received first, taking into account the provided options.

Definition

select: {
      <CS extends Channel.Read<any>[], RT>(channels: CS, options: {
        signal?: AbortSignal | undefined;
        timeoutMs?: number | undefined;
        recover: (channelError: Channel.Error) => RT;
      }): Promise<RT | {
        [K in keyof CS]: Channel.MessageType<CS[K]>;
      }[number]>;
      <CS extends Channel.Read<any>[]>(channels: CS, options?: {
        signal?: AbortSignal | undefined;
        timeoutMs?: number | undefined;
        recover?: undefined;
      }): Promise<{
        [K in keyof CS]: Channel.MessageType<CS[K]>;
      }[number]>;
    };

selectMap

Resolves, from the given tuples of channels and channel value handlers, the result of applying the corresponding channel handler to the first channel value that is received. options.

Definition

selectMap: {
      <TS extends any[], HS extends {
        [K in keyof TS]: [Channel.Read<TS[K]>, (value: TS[K]) => any];
      }>(options?: {
        signal?: AbortSignal | undefined;
        timeoutMs?: number | undefined;
        recover?: undefined;
      }, ...cases: HS & {
        [K in keyof TS]: [Channel.Read<TS[K]>, (value: TS[K]) => any];
      }): Promise<{
        [K in keyof HS]: Promise<ReturnType<HS[K][1]>>;
      }[number]>;
      <TS extends any[], HS extends {
        [K in keyof TS]: [Channel.Read<TS[K]>, (value: TS[K]) => any];
      }, RT>(options: {
        signal?: AbortSignal | undefined;
        timeoutMs?: number | undefined;
        recover: (channelError: Channel.Error) => RT;
      }, ...cases: HS & {
        [K in keyof TS]: [Channel.Read<TS[K]>, (value: TS[K]) => any];
      }): Promise<{
        [K in keyof HS]: Promise<ReturnType<HS[K][1]>>;
      }[number] | RT>;
    };

Methods

create

Returns a new Channel instance that can be used to synchronize asynchronous processes within a single thread.

Definition

create<T = void>(options?: Channel.Config): Channel<T>;

Type parameters

NameDefaultDescription
Tvoidthe channel message type

Parameters

NameTypeDescription
optionsChannel.Config(optional) the options used to create the channel
- capacity: (optional) the buffer size of the channel
- validator: (optional) a function taking a message and returning true if the message is of a valid type, false otherwise