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

Type Parameters

  • A extends Actor<I, T, O>

    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.

Hierarchy (view full)

Implements

Constructors

Properties

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

The name for this bus.

Default

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

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>

      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>[]

    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.

Generated using TypeDoc