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

    Function idempotent

    • idempotent — make duplicate dispatches a no-op against the handler/backend.

      The client-side half of exactly-once delivery: it collapses repeats of the same logical command — double-clicked Checkout, an auto-retry, a reconnect that replays a queued action — so the handler (and the backend it calls) runs once. Concurrent duplicates share the first in-flight promise; sequential duplicates within ttl get the cached result. Failures are NOT cached, so a genuine retry after an error still runs.

      Pairs with serialize (orders same-key commands locally) and with the HTTP bridge, which forwards the stamped cmd.meta.idempotencyKey as an Idempotency-Key header so the backend can reject the duplicate write too — the wire half of exactly-once. Register idempotent at a HIGHER priority than the transport so the key is stamped before the request is built.

      Parameters

      Returns AsyncPlugin

      const bus = createAsyncCommandBus();
      bus.use(idempotent({ actions: ['order*'] }), { priority: 100 }); // outermost
      bus.use(createHttpBridge({ endpoint: '/commands', csrf: true }));
      // two rapid orderCreate dispatches → one handler run, one backend write