Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Mediator<A, I, T, O>

A mediator can mediate an action over a bus of actors.

It does the following:

  1. Accepts an action in {@link Mediator#mediate}.
  2. Sends the action to the bus to test its applicability on all actors.
  3. It mediates over these test results.
  4. It selects the best actor.
  5. The action is run by the best actor, and the result if returned.

The mediates and best parts are filled in by subclasses of this abstract Mediator class.

Type parameters

  • A: Actor<I, T, O>

    The type of actor to mediator over.

  • 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

Properties

Methods

Constructors

Protected constructor

Properties

Readonly bus

bus: Bus<A, I, T, O>

Readonly name

name: string

Methods

mediate

  • mediate(action: I): Promise<O>
  • Mediate for the given action.

    This will send the test action on all actors in the bus. The action will be run on the actor that tests best, of which the result will be returned.

    Parameters

    • action: I

      The action to mediate for.

    Returns Promise<O>

    A promise that resolves to the mediation result.

mediateActor

  • mediateActor(action: I): Promise<A>
  • Mediate for the given action to get an actor.

    This will send the test action on all actors in the bus. The actor that tests best will be returned.

    Parameters

    • action: I

      The action to mediate for.

    Returns Promise<A>

    A promise that resolves to the best actor.

Protected Abstract mediateWith

  • mediateWith(action: I, testResults: IActorReply<A, I, T, O>[]): Promise<A>
  • Mediate for the given action with the given actor test results for the action.

    One actor must be returned that provided the best test result. How 'best' is interpreted, depends on the implementation of the Mediator.

    Parameters

    • action: I

      The action to mediate for.

    • testResults: IActorReply<A, I, T, O>[]

    Returns Promise<A>

    A promise that resolves to the best actor.

publish

  • Publish the given action in the bus.

    This will send the test action on all actors in the bus. All actor replies will be returned.

    Parameters

    • action: I

      The action to mediate for.

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

    The list of actor replies.

Generated using TypeDoc