Skip to main content

Module lifecycle

Module lifecycle 

Source
Expand description

Bar lifecycle events and rollback-safe, idempotent recomputation. Bar lifecycle events and rollback-safe, idempotent recomputation.

Indicator::on_bar takes a single incoming bar and permanently advances the indicator’s state — it has no notion of a bar that is still forming versus one that has closed, and no way to reprocess a bar without double-counting it.

BarLifecycle names the four events a feed can emit for a given timestamp. LifecycleRunner wraps any Indicator + Clone and makes BarLifecycle::Update/BarLifecycle::Correction safe to call repeatedly: it always recomputes from the last confirmed checkpoint rather than mutating forward, so re-delivering the same revised bar is idempotent and never double-applies a still-forming bar’s data.

LifecycleRunner keeps two checkpoints for the last confirmed bar: the state immediately before it was applied and the state immediately after. A BarLifecycle::Correction (or a repeated BarLifecycle::Confirmed for the same timestamp) restores the pre-bar checkpoint and applies the revised bar exactly once, so the corrected bar replaces the original rather than stacking on top of it. Only the most recently confirmed bar can be corrected this way — a correction or an out-of-order confirmation targeting an older timestamp is rejected with LifecycleError rather than silently mutating an unrelated state.

Requiring Clone is a deliberate, honest scope limit: it is the only mechanism that works generically across arbitrary indicator internals without adding a second, hand-written snapshot/restore method to every Indicator impl. Most indicator structs in this crate do not yet derive Clone; adding it is a mechanical, low-risk follow-up left to indicator authors as they adopt LifecycleRunner, not a blanket change bundled into this module.

Structs§

LifecycleRunner
Wraps an Indicator + Clone so BarLifecycle::Open/BarLifecycle::Update events can be replayed any number of times without permanently mutating state, and only BarLifecycle::Confirmed/BarLifecycle::Correction commit a new checkpoint.

Enums§

BarLifecycle
A bar-lifecycle event for a single timestamp.
LifecycleError
An error produced by LifecycleRunner::on_event when an event cannot be applied without losing or misrepresenting state.