Class BusIndexed<A, I, T, O>

A bus that indexes identified actors, so that actions with a corresponding identifier can be published more efficiently.

Multiple actors with the same identifier can be subscribed.

If actors or actions do not have a valid identifier, then this will fallback to the normal bus behaviour.

Bus

Type Parameters

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

    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)

Constructors

Properties

actionIdentifierFields: string[]
actorIdentifierFields: string[]
actors: A[] = []
actorsIndex: Record<string, A[]> = {}
dependencyLinks: Map<A, A[]> = ...
failMessage: string
name: string

The name for this bus.

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

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

  • Parameters

    • action: I

    Returns string

  • Parameters

    • actor: A

    Returns undefined | string[]

  • Invoked when an action was run by an actor.

    Parameters

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

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

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

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