vapor-chamber API reference - v1.3.0
    Preparing search index...

    Interface CommandPool

    CommandPool — pre-allocates Command objects in a circular buffer to eliminate garbage collection pauses during dispatch bursts. When the pool is exhausted, it wraps around and reuses the oldest slot.

    Important: The pool is a standalone utility — bus.dispatch() still creates its own Command internally and stamps meta (ts, id, correlationId). Pooled commands do NOT have meta set. Use pool.acquire() for the action/target/payload, then pass those values to bus.dispatch(cmd.action, cmd.target, cmd.payload). The bus will create its own internal command with proper metadata.

    Thread-safety note: single-threaded JS means no locking required.

    const pool = createCommandPool(64);
    const cmd = pool.acquire('cartAdd', cart, { id: 1 });
    bus.dispatch(cmd.action, cmd.target, cmd.payload); // bus stamps its own meta

    pool.stats(); // { size: 64, acquired: 1, cursor: 1 }
    pool.reset(); // Reset cursor and clear all slots
    interface CommandPool {
        acquire(action: string, target: any, payload?: any): Command;
        stats(): { size: number; acquired: number; cursor: number };
        reset(): void;
        size: number;
    }
    Index

    Methods

    Properties

    Methods

    • Acquire a command object from the pool. Reuses slots in a circular fashion.

      Parameters

      • action: string
      • target: any
      • Optionalpayload: any

      Returns Command

    • Current pool statistics.

      Returns { size: number; acquired: number; cursor: number }

    • Reset the pool — clears all slots and resets cursor.

      Returns void

    Properties

    size: number

    Pool capacity.