arvo-event-handler
    Preparing search index...

    Class SimpleMachineMemory<T>

    In-memory implementation of machine state storage for single-instance NodeJS applications.

    const memory = new SimpleMachineMemory();
    const orchestrator = createArvoOrchestrator({
    memory,
    machines: [workflow]
    });

    Concurrency Limitations

    This implementation is NOT concurrency-safe. Lock acquisition is not atomic, making it unsuitable for parallel event processing where multiple handlers might process events for the same workflow simultaneously.

    Safe Usage:

    • SimpleEventBroker (sequential event processing)
    • Isolated handlers without shared durable state requirements

    Unsafe Usage:

    • In-memory parallel/concurrent event brokers (e.g., p-queue with prefetch > 1)

    For concurrent in-process event processing, use the concurrency-safe memory backend from the @arvo-tools/concurrent package, which provides atomic lock operations suitable for parallel execution within a single process.

    Unsuitable For:

    • Multi-instance deployments
    • Distributed systems requiring shared state across processes

    For these scenarios, implement or use a database-backed memory backend (Redis, PostgreSQL, DynamoDB, etc.) that provides distributed state persistence and atomic locking across instances. You can also explore the Arvo tool eco-system @arvo-tools

    Type Parameters

    • T extends Record<string, any> = Record<string, any>

    Implements

    Index

    Constructors

    Methods

    • Optional cleanup hook invoked during successful workflow completion.

      The orchestrator calls this automatically when a workflow instance:

      1. Reaches a final completion state (terminal state or returns output)
      2. Successfully persists the final workflow state to storage

      This executes AFTER final state persistence but BEFORE the completion event is emitted back to the initiator. This ordering ensures the final state is durably saved before cleanup runs, while allowing cleanup logic to complete before the workflow signals completion to external systems.

      IMPORTANT: This hook is NOT called when orchestration execution fails (e.g., lock acquisition failure, state persistence failure, handler errors). It only executes for workflows that successfully reach their final state.

      Receives the same state transition data as write() to enable intelligent cleanup decisions based on how the workflow completed and what changed in the final step.

      This hook enables custom memory management strategies:

      • Mark state as eligible for garbage collection based on final state values
      • Archive completed workflows to cold storage with state-dependent retention
      • Implement conditional retention policies (e.g., keep failures longer than successes)
      • Extract specific data from final state for long-term analytics storage
      • Compare final vs previous state to determine appropriate storage tier
      • Trigger external cleanup processes with workflow completion context

      Implementations are not required to delete state immediately - they can implement whatever retention/archival strategy suits their operational needs.

      Parameters

      • id: string

        Workflow instance identifier (event.subject)

      Returns Promise<void>

    • Attempts to acquire lock for machine instance

      Parameters

      • id: string

        Machine instance ID

      Returns Promise<boolean>

      Success status of lock acquisition

      When id is empty or undefined

    • Gets stored state for a machine instance

      Parameters

      • id: string

        Machine instance ID

      Returns Promise<T | null>

      State data or null if not found

      When id is empty or undefined

    • Releases lock for machine instance

      Parameters

      • id: string

        Machine instance ID

      Returns Promise<boolean>

      True when lock is released

      When id is empty or undefined

    • Stores state for a machine instance

      Parameters

      • id: string

        Machine instance ID

      • data: T

        State to store

      Returns Promise<void>

      When id is empty/undefined or data is null/undefined