Skip to main content

PendingWorker

Struct PendingWorker 

Source
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: FlushTimer

Implementations§

Source§

impl<T, P> PendingWorker<T, P>

Source

pub fn new(flush_policy: P) -> Self

Creates an empty worker without starting a timer or runtime task.

Source

pub fn is_empty(&self) -> bool

Returns whether the worker has no submissions, including zero-row items.

Source

pub fn total_rows(&self) -> usize

Returns the pending row count before ownership is transferred to the caller.

Source

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.

Source

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>

Source

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.

Source

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.

Source

fn refresh_deadline(&mut self)

Auto Trait Implementations§

§

impl<T, P> !RefUnwindSafe for PendingWorker<T, P>

§

impl<T, P> !UnwindSafe for PendingWorker<T, P>

§

impl<T, P> Freeze for PendingWorker<T, P>
where P: Freeze,

§

impl<T, P> Send for PendingWorker<T, P>
where P: Send, T: Send,

§

impl<T, P> Sync for PendingWorker<T, P>
where P: Sync, T: Sync,

§

impl<T, P> Unpin for PendingWorker<T, P>
where P: Unpin, T: Unpin,

§

impl<T, P> UnsafeUnpin for PendingWorker<T, P>
where P: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.