createStoredContinuationCodec

API Reference for createStoredContinuationCodec.

createStoredContinuationCodec()

Create a single-use, storage-backed string continuation codec.

import { createStoredContinuationCodec } from 'run';

const continuationCodec = createStoredContinuationCodec({
  storage: {
    set: (key, value) => store.set(key, value),
    acquire: (key, claimId, context) =>
      store.claim(key, {
        claimId,
        claimMs: 30_000,
        signal: context?.abortSignal,
      }),
    consume: (key, claimId) => store.deleteIfClaimedBy(key, claimId),
    release: (key, claimId) => store.releaseIfClaimedBy(key, claimId),
  },
});

The storage methods describe a temporary claim on a continuation:

  • acquire() gives one caller exclusive access without deleting the value.
  • consume() permanently deletes the value after validation succeeds.
  • release() makes the value available again after cancellation or validation failure.

The codec calls these methods automatically. Application code does not need to choose when to consume or release a continuation.

acquire() must create a claim that expires automatically after a bounded interval. Automatic expiry makes the continuation available again if the process crashes before it can call consume() or release(). Both finalization methods must only modify the record when the supplied claim identifier matches the record's current claim.

Import

import { createStoredContinuationCodec } from 'run';

API Signature

Parameters

Prop

Type

Returns

Prop

Type