pub struct BackgroundSettlementTracker { /* private fields */ }server only.Expand description
Shared in-flight counter for background settlement tasks.
Created by the operator at startup, attached to a Paygate via
PaygateBuilder::with_settlement_tracker, and drained at shutdown
via Paygate::settlement_tracker + Self::wait_for_drain. The
implementation is
lock-free in the steady state: a single AtomicUsize for the
counter and a tokio::sync::Notify for the drain wake-up.
Cloning the tracker is cheap and shares state, so it can be passed to multiple paygates serving the same shutdown channel (for example, when one process hosts several routes behind different price tags).
Implementations§
Source§impl BackgroundSettlementTracker
impl BackgroundSettlementTracker
Sourcepub fn in_flight(&self) -> usize
pub fn in_flight(&self) -> usize
Returns the current approximate number of in-flight settlement
tasks. Useful for /healthz style readiness probes.
Sourcepub async fn wait_for_drain(&self, timeout: Duration) -> Result<(), usize>
pub async fn wait_for_drain(&self, timeout: Duration) -> Result<(), usize>
Awaits the in-flight count to reach zero, bounded by timeout.
Returns Ok(()) once drained, or Err(remaining) after the
deadline with the count of still-running tasks.
§Errors
Returns the count of in-flight tasks when the timeout elapses before the drain completes. Callers may then choose to abort the runtime, log, or extend the deadline.
Trait Implementations§
Source§impl Clone for BackgroundSettlementTracker
impl Clone for BackgroundSettlementTracker
Source§fn clone(&self) -> BackgroundSettlementTracker
fn clone(&self) -> BackgroundSettlementTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more