pub struct UsageWriter { /* private fields */ }Expand description
Handle to the writer task.
Implementations§
Source§impl UsageWriter
impl UsageWriter
Sourcepub fn spawn(
sink: Arc<dyn UsageSink>,
clock: Arc<dyn Clock>,
config: UsageWriterConfig,
) -> Result<(UsageRecorder, UsageWriter), UsageWriterConfigError>
pub fn spawn( sink: Arc<dyn UsageSink>, clock: Arc<dyn Clock>, config: UsageWriterConfig, ) -> Result<(UsageRecorder, UsageWriter), UsageWriterConfigError>
Validate config and start the writer task. Returns the cloneable
request-side UsageRecorder and this owning handle, which must be
retained and shut down; dropping it aborts the task and loses
whatever is queued. Must be called within a Tokio runtime.
§Errors
UsageWriterConfigError when config fails validation; nothing is
started.
Sourcepub fn health(&self) -> WriterHealth
pub fn health(&self) -> WriterHealth
The writer’s accounting health, readable at any time — the same numbers
UsageRecorder::health reports, for an embedder that holds this half.
Sourcepub async fn shutdown(self) -> Result<WriterStats, WriterShutdownError>
pub async fn shutdown(self) -> Result<WriterStats, WriterShutdownError>
Flush everything already enqueued, then stop. Call this before releasing leases — events must land while their lease is live.
A writer task that died instead of reporting yields
WriterShutdownError carrying the charges it was still holding —
never a zeroed WriterStats, which would be indistinguishable from
a clean shutdown (INVARIANTS.md GL-8).