Class Actor<TMessage>

Reference: https://www.youtube.com/watch?v=7erJ1DV_Tlo&ab_channel=jasonofthel33t

Actor: Fundamental unit of computation Actor needs to embody

  • Processing
  • Storage
  • Communication

"One ant is no ant" - "One human is no human" - "One actor is no actor" Actors live within systems

Fundamental Properties:

  • Receive messages, in response of this it can"
    • Create actors
    • Send messages (to other actors and itself)
    • Designates what to do with the next message it receives

Type Parameters

  • TMessage extends ActorEvent = ActorEvent

Hierarchy

  • Actor

Constructors

Properties

Accessors

Methods

Constructors

Properties

address: string
stop$: Observable<ActorEvent<unknown, Event<any>>> = ...

Stream of stop events (might be useful to know when the actor stops)

Accessors

Methods

  • Subscribes to an observable of events when there is an emission will send the event to a recipient (actor reference) when specified and to itself when not. completes when stop message is send to the actor.

    Example

    import { Actor, createEvent } from 'reactive-actor';

    export const getUsers = createEvent('[Users] Get Users');

    export const getUsersSuccess = createEvent<GitHubUser[]>( '[Users] Get Users Success' );

    export const getUsersFail = createEvent('[Users] Get Users Fail');

    export type UsersActorEvents = ReturnType;

    export class UsersActor extends Actor { // Reference to logger actor private readonly logger = new Actor('logger');

    // Recipient is not define thus will send the resulting event to itself private readonly getUsers$ = this.messages$.pipe( ofType(getUsers), exhaustMap(() => ajax<GitHubUser[]>(https://api.github.com/users?per_page=5).pipe( map(({ response }) => getUsersSuccess(response)), catchError((err) => of(getUsersFail(err))) ) ) );

    // Recipient is define thus will send event (getUsersFail) to specified recipient (logger) private readonly getUsersFail$ = this.messages$.pipe( ofType(getUsersFail), addRecipient(this.logger) );

    constructor() { super('users'); this.answer(this.getUsers$, this.getUsersFail$); } }

    Parameters

    Returns void

  • Method to send messages to the actor

    Parameters

    • message: TMessage

      we want to send to the actor

    Returns void

Generated using TypeDoc