Class Bus<A, I, T, O, TS>

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.

  • Actor
  • Mediator

Type Parameters

  • A extends Actor<I, T, O, TS>

    The actor type that can subscribe to the sub.

  • I extends IAction

    The input type of an actor.

  • T extends IActorTest

    The test type of an actor.

  • O extends IActorOutput

    The output type of an actor.

  • TS = undefined

    The test side data type.

Hierarchy (View Summary)

Implements

Constructors

Properties

actors: A[] = []
dependencyLinks: Map<A, A[]> = ...
failMessage: string
name: string

The name for this bus.

{<rdf:subject>}
observers: ActionObserver<I, O, TS>[] = []

Methods

  • 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

  • Invoked when an action was run by an actor.

    Parameters

    • actor: Actor<I, T, O, TS>

      The action on which the 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 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, TS>[]

    An array of reply objects. Each object contains a reference to the actor, and a promise to its Actor#test result.

  • Reorder the bus based on all present dependencies.

    Returns void

  • Subscribe the given actor to the bus. After this, the given actor can be unsubscribed from the bus by calling 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

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

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

    Parameters

    Returns void

  • 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.

  • 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.