Class Actor<I, T, O, TS>Abstract

An actor can act on messages of certain types and provide output of a certain type.

The flow of an actor is as follows:

  1. Send a message to Actor#test to test if an actor can run that action.
  2. If the actor can reply to the message, let the actor run the action using Actor#run.

An actor is typically subscribed to a bus, using which the applicability to an action can be tested.

Bus

Type Parameters

  • 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

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

    The actor will subscribe to the given bus when this constructor is called.

    Type Parameters

    Parameters

    • args: IActorArgs<I, T, O, TS>

      Arguments object

      • OptionalbeforeActors?: Actor<I, T, O, TS>[]

        Actor that must be registered in the bus before this actor.

      • bus: Bus<Actor<I, T, O, TS>, I, T, O, TS>

        The bus this actor subscribes to.

      • OptionalbusFailMessage?: string

        The message that will be configured in the bus for reporting failures.

        This message may be a template string that contains references to the executed action. For example, the following templated string is allowed: "RDF dereferencing failed: no actors could handle ${action.handle.mediaType}"

      • name: string

        The name for this actor.

        {<rdf:subject>}
        

    Returns Actor<I, T, O, TS>

    When required arguments are missing.

Properties

beforeActors: Actor<I, T, O, TS>[] = []

Actor that must be registered in the bus before this actor.

bus: Bus<Actor<I, T, O, TS>, I, T, O, TS>

The bus this actor subscribes to.

name: string

The name for this actor.

{<rdf:subject>}

Methods

  • Run the given action on this actor.

    In most cases, this method should not be called directly. Instead, #runObservable should be called.

    Parameters

    • action: I

      The action to run.

    • sideData: TS

    Returns Promise<O>

    A promise that resolves to the run result.

  • Run the given action on this actor AND invokes the Bus#onRun method.

    Parameters

    • action: I

      The action to run.

    • sideData: TS

    Returns Promise<O>

    A promise that resolves to the run result.

  • Check if this actor can run the given action, without actually running it.

    Parameters

    • action: I

      The action to test.

    Returns Promise<TestResult<T, TS>>

    A promise that resolves to the test result.