@laserware/stasis
    Preparing search index...

    Interface Channel<T>

    A channel is an object used to send and receive messages between tasks. Messages from senders are queued until an interested receiver request a message, and registered receiver is queued until a message is available.

    Every channel has an underlying buffer which defines the buffering strategy (fixed size, dropping, sliding)

    The Channel interface defines 3 methods: take, put and close

    interface Channel<T extends NotUndefined> {
        close(): void;
        flush(cb: (items: END | T[]) => void): void;
        put(message: T | END): void;
        take(cb: (message: T | END) => void): void;
    }

    Type Parameters

    • T extends NotUndefined
    Index

    Methods

    • Closes the channel which means no more puts will be allowed. All pending takers will be invoked with END.

      Returns void

    • Used to extract all buffered messages from the channel. The flush is resolved using the following rules

      • If the channel is closed and there are no buffered messages, then callback is invoked with END
      • Otherwise callback is invoked with all buffered messages.

      Parameters

      • cb: (items: END | T[]) => void

      Returns void

    • Used to put message on the buffer. The put will be handled using the following rules

      • If the channel is closed, then the put will have no effect.
      • If there are pending takers, then invoke the oldest taker with the message.
      • Otherwise put the message on the underlying buffer

      Parameters

      • message: T | END

      Returns void

    • Used to register a taker. The take is resolved using the following rules

      • If the channel has buffered messages, then callback will be invoked with the next message from the underlying buffer (using buffer.take())
      • If the channel is closed and there are no buffered messages, then callback is invoked with END
      • Otherwisecallback will be queued until a message is put into the channel

      Parameters

      • cb: (message: T | END) => void

      Returns void