Skip to main content
Version: Next

SnapshotStore <T>

A time-pruning, time-windowed store for LoadSnapshot values. All four built-in signals compose with one of these, and so can yours — it is the only part of their machinery worth reusing.

Index

Constructors

constructor

Methods

clear

  • clear(): void
  • Discards every retained snapshot. The built-in signals do this when they start, so that a session neither samples nor diffs against measurements from before the preceding downtime — pruning is relative to the newest snapshot rather than the wall clock, so stale entries would otherwise survive indefinitely. Clearing on start rather than on stop leaves a finished session readable.


    Returns void

getAll

  • getAll(): T[]
  • Direct, unwindowed access to the underlying array — used by signals whose handler needs the previous snapshot to compute a delta (e.g. the event loop and storage backend signals read the last entry to measure change since it).


    Returns T[]

getSample

  • getSample(sampleDurationMillis): T[]
  • Return all snapshots, or only those within the given time window.


    Parameters

    • optionalsampleDurationMillis: number

    Returns T[]

push

  • push(snapshot, now): void
  • Add a snapshot and prune entries older than the history window.


    Parameters

    • snapshot: T
    • now: Date = snapshot.createdAt

    Returns void

useSampleWindow

  • useSampleWindow(maxSampleWindowMillis): void
  • Sizes retention to the window the signal will be sampled over, as handed to it in start(). Until this is called nothing is pruned at all, so a signal that ignores its start context grows unboundedly.


    Parameters

    • maxSampleWindowMillis: number

    Returns void