Prelude API
    Preparing search index...

    Class Actor<M, S, R>

    An actor owns a piece of state and processes messages from its mailbox one at a time. It starts processing as soon as it is constructed.

    M - Message type.

    S - State type.

    R - Reply type returned by the handler and resolved by ask.

    Type Parameters

    • M
    • S = undefined
    • R = void

    Implements

    Index
    name?: string
    supervisor?: Supervisor

    Consulted when a failure is escalated. May be assigned after construction.

    • get done(): Promise<void>

      Settles when the actor has terminated: resolves after a normal stop or kill, rejects with the failure when the actor failed.

      Returns Promise<void>

    • get error(): unknown

      The failure that terminated the actor, if any.

      Returns unknown

    • get pending(): number

      Number of messages waiting in the mailbox (including senders blocked on a full mailbox).

      Returns number

    • get restarts(): number

      Number of restarts so far.

      Returns number

    • get state(): S

      Current state. Replaced on restart.

      Returns S

    • Returns Promise<void>

    • Enqueues a message and resolves with the handler's return value. Rejects with the handler's error, on timeout, on abort, or if the actor terminates before processing the message.

      Parameters

      Returns Promise<R>

    • Terminates immediately: aborts the in-flight handler's signal, drops queued messages as dead letters and rejects their asks. Resolves once the in-flight handler (if any) has settled; idempotent.

      Parameters

      • reason: unknown = ...

      Returns Promise<void>

    • Re-initialises the state via init, keeping the mailbox. If a message is in flight its signal is aborted and the restart happens once the handler settles; while the failure policy is running (no handler touching the state) it is applied immediately, so supervisors restarting siblings never wait on each other. Rejects if the actor has terminated; if init throws the actor fails with that error (policy-driven restarts, by contrast, retry through the policy).

      Returns Promise<void>

    • Enqueues a message. Resolves once the message is in the mailbox (waiting for room when the mailbox is bounded); rejects if the actor is not running or terminates before accepting it.

      Parameters

      • message: M

      Returns Promise<void>

    • Stops accepting messages, processes what is already queued and terminates. Resolves once the actor has terminated (for any reason); idempotent.

      Returns Promise<void>