Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Channel<T>

This interface represent a channel. It has 4 FIFO stacks plus some methods to operate with those sstacks.

Type parameters

  • T

Hierarchy

  • Channel

Implemented by

Index

Properties

__@asyncIterator

__@asyncIterator: function

This method allow us to use a channel as an async Iterable

Type declaration

    • (): AsyncIterableIterator<T>
    • Returns AsyncIterableIterator<T>

__computed

__computed: function[]

This stack will contain all the messages sended by the channel's users This stack will contain all the 'resolve' functions of the putters. When a process put a value into the channel a Promise is returned. The 'resolve' function of that Promise ends here This stack will contain all the 'resolve' functions of the takers. When a process take a value from the channel a Promise is returned. The 'resolve' function of that Promise ends here This stack will contain all the 'resolve' functions of the racers. When a process execute Channel.alts or Channel.select a Promise is returned. The 'resolve' function of that Promise ends here

Methods

areThereMessages

  • areThereMessages(): boolean

drain

  • drain(): Promise<T[]>
  • If there are no messages to be taken, the returned array will be empty

    Returns Promise<T[]>

    A promise that will be fulfilled with an array containing all the messages present into a channel

fulfillTheRacer

  • fulfillTheRacer(racer: function): void

isThereAPendingRacer

  • isThereAPendingRacer(): boolean

isThereAlreadyAPendingPutter

  • isThereAlreadyAPendingPutter(): boolean

isThereAlreadyAPendingTaker

  • isThereAlreadyAPendingTaker(): boolean

prependMessage

  • prependMessage(msg: T): void

put

  • put(msg: T): Promise<void>
  • If there is already a taker or a racer waiting a message, the returned promise will be immediately resolved

    If both a taker and a racer were waiting a message the priority is given to the taker that will retrieve the message

    Parameters

    • msg: T

      A value that will be forwarded into the channel

    Returns Promise<void>

    A promise that will be fulfilled when someone takes the msg from the channel

race

  • Transform a Channel into a Promise that wraps the channel itself. The promise will be fulfilled immediately if here is already a message ready to be taken. Otherwise the promise will be fulfilled with the channel when a process do a put operation, but only if there was no a waiting taker

    Returns Promise<Channel<T>>

    A promise wrapping a Channel

retrieveOldestMessage

  • retrieveOldestMessage(): T

retrieveOldestRacer

  • retrieveOldestRacer(): function

retrieveOldestTaker

  • retrieveOldestTaker(): function
  • Returns function

      • (msg: T): void
      • Parameters

        • msg: T

        Returns void

take

  • take(): Promise<T>
  • If there is already a message ready to be taken, the returned promise will be immediately resolved and the message read

    Returns Promise<T>

    A promise that will be fulfilled when someone put a message into the channel

unwaitOldestPutter

  • unwaitOldestPutter(): void

waitAPutter

  • waitAPutter(resolve: function): void
  • Parameters

    • resolve: function
        • (msg: T): void
        • Parameters

          • msg: T

          Returns void

    Returns void

waitATakerOrARacer

  • waitATakerOrARacer(resolve: function): void
  • Parameters

    • resolve: function
        • (): void
        • Returns void

    Returns void

waitTheChannel

  • waitTheChannel(resolve: function): void

Generated using TypeDoc