Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Bus<A, I, T, O>

A publish-subscribe bus for sending actions to actors to test whether or not they can run an action.

This bus does not run the action itself, for that a Mediator can be used.

see

Actor

see

Mediator

Type parameters

  • A: Actor<I, T, O>

    The actor type that can subscribe to the sub.

  • I: IAction

    The input type of an actor.

  • T: IActorTest

    The test type of an actor.

  • O: IActorOutput

    The output type of an actor.

Hierarchy

Implements

Index

Constructors

constructor

  • All enumerable properties from the args object are inherited to this bus.

    throws

    When required arguments are missing.

    Parameters

    Returns Bus

Properties

Protected Readonly actors

actors: A[] = []

Protected Readonly dependencyLinks

dependencyLinks: Map<A, A[]> = new Map()

Readonly name

name: string

Protected Readonly observers

observers: ActionObserver<I, O>[] = []

Methods

addDependencies

  • addDependencies(dependent: A, dependencies: A[]): void
  • Indicate that the given actor has the given actor dependencies.

    This will ensure that the given actor will be present in the bus before the given dependencies.

    Parameters

    • dependent: A

      A dependent actor that will be placed before the given actors.

    • dependencies: A[]

      Actor dependencies that will be placed after the given actor.

    Returns void

onRun

  • onRun(actor: Actor<I, T, O>, action: I, output: Promise<O>): void
  • Invoked when an action was run by an actor.

    Parameters

    • actor: Actor<I, T, O>

      The action on which the {@link Actor#run} method was invoked.

    • action: I

      The original action input.

    • output: Promise<O>

      A promise resolving to the final action output.

    Returns void

publish

  • Publish an action to all actors in the bus to test if they can run the action.

    Parameters

    • action: I

      An action to publish

    Returns IActorReply<A, I, T, O>[]

    {IActorReply<A extends Actor<I, T, O>, I extends IAction, T extends IActorTest, O extends IActorOutput>[]} An array of reply objects. Each object contains a reference to the actor, and a promise to its {@link Actor#test} result.

reorderForDependencies

  • reorderForDependencies(): void

subscribe

  • subscribe(actor: A): void
  • Subscribe the given actor to the bus. After this, the given actor can be unsubscribed from the bus by calling {@link Bus#unsubscribe}.

    An actor that is subscribed multiple times will exist that amount of times in the bus.

    Parameters

    • actor: A

      The actor to subscribe.

    Returns void

subscribeObserver

  • Subscribe the given observer to the bus. After this, the given observer can be unsubscribed from the bus by calling {@link Bus#unsubscribeObserver}.

    An observer that is subscribed multiple times will exist that amount of times in the bus.

    Parameters

    Returns void

unsubscribe

  • unsubscribe(actor: A): boolean
  • Unsubscribe the given actor from the bus.

    An actor that is subscribed multiple times will be unsubscribed only once.

    Parameters

    • actor: A

      The actor to unsubscribe

    Returns boolean

    If the given actor was successfully unsubscribed, otherwise it was not subscribed before.

unsubscribeObserver

  • Unsubscribe the given observer from the bus.

    An observer that is subscribed multiple times will be unsubscribed only once.

    Parameters

    Returns boolean

    If the given observer was successfully unsubscribed, otherwise it was not subscribed before.

Generated using TypeDoc