Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LabeledConditionalVariableManager<Label, Result>

Class which manages a set of conditional variables. Each conditional variable has an associated label, aka identifier.
These conditional variables are used to synchronize access to operation. Namely to ensure that operation will be performed only once by the AwaiterRole.PRODUCER, and then, in case operation is still performing, other AwaiterRole.CONSUMER can await operation promise, until AwaiterRole.PRODUCER fulfills it.

Type parameters

  • Label

  • Result

Hierarchy

  • LabeledConditionalVariableManager

Constructors

constructor

Accessors

size

  • get size(): number
  • Get number of the labels locks has been acquired on.

    Returns number

Methods

forcedNotify

  • forcedNotify(filter: "@all" | UnaryPredicate<Label>): void
  • Notify all consumers on filtered labels by forcibly rejecting promises consumers are waiting on. This will basically flush locks from all filtered labels.

    Parameters

    • filter: "@all" | UnaryPredicate<Label>

      Filter labels on which forced notify needs to be applied.

    Returns void

notifyAll

  • notifyAll(label: Label, result?: Optional<Result> | Error): void
  • Notify consumers about computation completion.
    Although either producer or consumers can call this function, it is recommended that producer who successfully acquired lock to notify consumers.

    Parameters

    • label: Label

      Label to notify on.

    • Optional result: Optional<Result> | Error

      Result of the computation or it's error.

    Returns void

wait

  • Waits on label.

    When lock is acquired already, Promise of the locked mutex is returned. This allows consumers to wait on provided promise, until producer who firstly acquired lock, finishes computation.

    Depending on the locked operation type, the following combinations are allowed:

    Acquired Requested Explanation
    LockedOperationType.WRITE NONE When operation was locked for write, i.e. some resource is modified, you can't overwrite it or read intermediary results until operation finishes.
    LockedOperationType.READ LockedOperationType.READ When operation was locked for read, you can only perform another reads and not allowed to write until all reads have been completed.

    If `timeout` is provided, and consumers are not notified in the given interval, promise will be forcibly rejected.

    After operation has been completed, AwaiterRole.PRODUCER should call LabeledConditionalVariableManager.notifyAll to notify consumers about operation completion.

    Parameters

    • label: Label

      Label to wait on.

    • operation: LockedOperationType
    • Optional timeout: null | number

    Returns WaitStatus<Optional<Result>>

    Waiting status.

Static formatAwaiterRole

  • Format AwaiterRole enum into it's corresponding string representation.

    Parameters

    Returns string

    String representation.

Static formatLockedOperation

  • Format LockedOperationType bitwise enum into it's corresponding string representation.

    Parameters

    Returns string

    String representation.