pub struct PendingWorker<T, P> {
batch: PendingBatch<T>,
flush_policy: P,
flush_timer: FlushTimer,
}Expand description
Batch state for one grouping key, independent of the caller’s event loop.
The caller owns channels, idle/shutdown decisions, execution limits, task spawning and business completion. Taking a batch transfers its items to the caller; no background task is started by this worker.
Fields§
§batch: PendingBatch<T>§flush_policy: P§flush_timer: FlushTimerImplementations§
Source§impl<T, P> PendingWorker<T, P>
impl<T, P> PendingWorker<T, P>
Sourcepub fn new(flush_policy: P) -> Self
pub fn new(flush_policy: P) -> Self
Creates an empty worker without starting a timer or runtime task.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the worker has no submissions, including zero-row items.
Sourcepub fn total_rows(&self) -> usize
pub fn total_rows(&self) -> usize
Returns the pending row count before ownership is transferred to the caller.
Sourcepub async fn wait_flush(&mut self)
pub async fn wait_flush(&mut self)
Waits for a timer wakeup without taking or executing the batch.
Cancellation is safe: selecting another event does not lose items or
reset the deadline. After a wakeup, call Self::take_ready with
FlushTrigger::Deadline. An empty or unarmed worker stays pending.
Sourcepub fn take_pending(&mut self) -> Option<Vec<T>>
pub fn take_pending(&mut self) -> Option<Vec<T>>
Takes all pending submissions regardless of policy, for example on shutdown.
Returns None for an empty batch. The caller decides whether to execute
inline, acquire a flush permit or discard the returned items.
Source§impl<T, P: FlushPolicy> PendingWorker<T, P>
impl<T, P: FlushPolicy> PendingWorker<T, P>
Sourcepub fn submit(&mut self, item: T, total_rows: usize)
pub fn submit(&mut self, item: T, total_rows: usize)
Appends one complete submission and arms the policy’s deadline.
Call Self::take_ready with FlushTrigger::Submission afterwards to
check whether this submission triggered a flush. Timer-backed policies
require a Tokio runtime with time enabled.
§Panics
Panics if arming a new timer outside a Tokio runtime with time enabled.
Sourcepub fn take_ready(&mut self, trigger: FlushTrigger) -> Option<Vec<T>>
pub fn take_ready(&mut self, trigger: FlushTrigger) -> Option<Vec<T>>
Takes the batch only when the policy permits flushing for this event.
Like Self::submit, this may arm a timer and requires a time-enabled
Tokio runtime when the policy starts using deadlines.