pub struct ManagedBatchWriter<T, E> { /* private fields */ }Expand description
Explicitly started and stopped buffering with one owned worker and bounded overflow.
The sink must be cancellation-safe: interruption means an unknown commit, not a safe retry.
T: Clone permits retaining originals while an owned copy is passed to persistence.
Observers receive a bounded channel created by the caller; callbacks run outside persistence.
No automatic retry occurs, including for Retryable failures.
Implementations§
Source§impl<T: Clone + Send + 'static, E: Send + Sync + 'static> ManagedBatchWriter<T, E>
impl<T: Clone + Send + 'static, E: Send + Sync + 'static> ManagedBatchWriter<T, E>
Sourcepub fn new<F, Fut>(
config: BufferedBatchConfig,
overflow: OverflowPolicy,
events: Option<Sender<BufferedWriterEvent>>,
sink: F,
) -> Self
pub fn new<F, Fut>( config: BufferedBatchConfig, overflow: OverflowPolicy, events: Option<Sender<BufferedWriterEvent>>, sink: F, ) -> Self
Constructs an idle owner. Call start from the runtime startup phase.
Sourcepub async fn start(&self) -> Result<(), BufferedWriterState>
pub async fn start(&self) -> Result<(), BufferedWriterState>
Starts exactly once. Returns the current state if startup has already been attempted.
§Errors
Returns the current state unless this is the first start from Created.
Sourcepub async fn record(
&self,
item: T,
) -> Result<RecordAdmission, RecordError<T, E>>
pub async fn record( &self, item: T, ) -> Result<RecordAdmission, RecordError<T, E>>
Admits a record or returns it when rejected. Cancellation of a direct waiter does not cancel its accepted record: the owned worker still persists or retains it.
§Errors
Rejection returns the record. A direct persistence failure retains it in the owner.
Sourcepub fn begin_drain(&self)
pub fn begin_drain(&self)
Atomically stops admission. Accepted records remain owned and can still flush.
Sourcepub async fn flush(&self, deadline: Instant) -> Result<(), BufferFlushError<E>>
pub async fn flush(&self, deadline: Instant) -> Result<(), BufferFlushError<E>>
Flushes records admitted before this future’s first poll, using a caller deadline. Later admissions cannot extend the captured scope or satisfy it through another lane. Dropping this future leaves accepted writes owned by the worker. A failed lane does not prevent draining other records in this scope. An expired deadline starts no new flush work. An already acknowledged scope succeeds even after the deadline. Normal threshold/timer writes and other flush callers proceed independently of this future’s scope and deadline.
§Errors
Returns a lifecycle error, the original in-scope write failure, or deadline exhaustion.
Sourcepub fn retry_failed(&self)
pub fn retry_failed(&self)
Clears only failures classified as safe to retry. Unknown/permanent records stay blocked.
Sourcepub async fn stop(&self, deadline: Instant) -> BufferStopReport<E>
pub async fn stop(&self, deadline: Instant) -> BufferStopReport<E>
Stops admission, drains until deadline/failure, then cancels and joins the owned worker. Repeated/concurrent calls share the same handle; cancelling a stop caller leaves the handle available for another caller. Dependencies must close only after this future returns.
Sourcepub fn snapshot(&self) -> BufferedWriterSnapshot<E>
pub fn snapshot(&self) -> BufferedWriterSnapshot<E>
Captures independent state and counters, without invoking observer code.
Sourcepub fn unconfirmed(&self) -> Vec<T>
pub fn unconfirmed(&self) -> Vec<T>
Copies all unacknowledged records for reconciliation; never implicitly replays them. Stop first to obtain a stable recovery snapshot.