Skip to content

@statesync/persistence


@statesync/persistence / SaveThrottlingOptions

Interface: SaveThrottlingOptions

Defined in: persistence/src/types.ts:575

Options for controlling how frequently snapshots are saved to storage.

Supports debouncing, throttling, leading-edge saves, and a maximum wait cap. These options help balance write frequency against data freshness, especially during rapid or continuous state updates.

Example

typescript
const throttling: SaveThrottlingOptions = {
  debounceMs: 300,    // Wait 300ms of silence before saving
  maxWaitMs: 2000,    // But never wait more than 2s total
};

Properties

debounceMs?

ts
optional debounceMs: number;

Defined in: persistence/src/types.ts:583

Debounce delay in milliseconds. The save is postponed until no new snapshots arrive for this duration ("wait for silence").

Best for high-frequency updates where only the final state matters (e.g., text input, slider dragging).


leading?

ts
optional leading: boolean;

Defined in: persistence/src/types.ts:600

If true, the very first update triggers an immediate save before the debounce/throttle timer starts.

Default Value

false


maxWaitMs?

ts
optional maxWaitMs: number;

Defined in: persistence/src/types.ts:609

Maximum time in milliseconds to wait before forcing a save, even if debounce keeps resetting. Prevents indefinite delay during continuous updates.

Only meaningful when debounceMs is also set.


throttleMs?

ts
optional throttleMs: number;

Defined in: persistence/src/types.ts:592

Throttle interval in milliseconds. At most one save will occur per interval, regardless of how many snapshots arrive.

Best when you want periodic saves during continuous updates (e.g., real-time collaboration).

Released under the MIT License.