pub struct WorkerPump<T> {
capacity: usize,
drain_logs_each_tick: bool,
_marker: PhantomData<fn() -> T>,
}Expand description
Runs a worker thread in parallel with a main-thread pump loop.
See the module documentation for the longjmp-safety contract and a usage example.
Fields§
§capacity: usizeCapacity of the bounded MPSC channel between worker and pump.
drain_logs_each_tick: boolWhether to drain the cross-thread log queue on every pump tick.
_marker: PhantomData<fn() -> T>Implementations§
Source§impl<T: Send + 'static> WorkerPump<T>
impl<T: Send + 'static> WorkerPump<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new WorkerPump with default settings.
Defaults:
- channel capacity: 64
drain_logs_each_tick:true
Sourcepub fn channel_capacity(self, n: usize) -> Self
pub fn channel_capacity(self, n: usize) -> Self
Set the capacity of the bounded MPSC channel.
The default is 64. A larger capacity allows the worker to get further ahead of the pump; a capacity of 0 makes every send synchronous (rendezvous channel).
When the channel is full the worker blocks on tx.send until the pump
drains a slot. If the pump panics or a longjmp fires, rx is dropped
as part of scope unwinding, which unblocks tx.send with an Err and
lets the worker exit cleanly.
Sourcepub fn drain_logs_each_tick(self, on: bool) -> Self
pub fn drain_logs_each_tick(self, on: bool) -> Self
Control whether the cross-thread log queue is drained on every pump tick.
Default: true. Set to false if the consumer manages its own log
drain cadence (e.g. it calls drain_log_queue() explicitly at
coarser granularity).
Has no effect when the log feature is disabled.
Sourcepub fn run<R, W, P>(self, worker: W, pump: P) -> Result<R, WorkerError>
pub fn run<R, W, P>(self, worker: W, pump: P) -> Result<R, WorkerError>
Run the worker/pump pair and return the worker’s result.
workerruns on a scoped background thread. It receives aSyncSender<T>and sends messages to the pump. Whenworkerreturns (success or error) it should droptx; the pump’s receive loop then terminates naturally.pumpis called on the current (main R) thread for every message the worker sends.
run returns Ok(R) on success, or Err if the worker returned an
error or panicked.
§Panics
If the worker thread panics, run returns
Err("WorkerPump worker panicked").
If the pump closure panics, the panic propagates normally through
thread::scope’s Drop (which joins the worker), and then out of
run. When called from inside an #[miniextendr] body the outer
R_UnwindProtect catches it and converts it to an R error.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for WorkerPump<T>
impl<T> RefUnwindSafe for WorkerPump<T>
impl<T> Send for WorkerPump<T>
impl<T> Sync for WorkerPump<T>
impl<T> Unpin for WorkerPump<T>
impl<T> UnsafeUnpin for WorkerPump<T>
impl<T> UnwindSafe for WorkerPump<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeEq<MaybeUninit<T>> for T
impl<T> SizeEq<MaybeUninit<T>> for T
type CastFrom = CastSizedExact
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreimpl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> InvariantsEq<ManuallyDrop<T>> for Twhere
T: ?Sized,
impl<T> InvariantsEq<T> for Twhere
T: ?Sized,
impl<T> InvariantsEq<Unalign<T>> for T
impl<T> InvariantsEq<Wrapping<T>> for T
impl<Src, Dst, A, SV, DV, R> MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
impl<Src, Dst, A, SV, DV> MutationCompatible<Src, A, SV, DV, BecauseInvariantsEq> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
Dst: TransmuteFrom<Src, SV, DV> + InvariantsEq<Src> + ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Cell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ManuallyDrop<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ReadOnly<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<Src, Dst> TransmuteFrom<Src, Initialized, Initialized> for Dst
impl<Src, Dst, V> TransmuteFrom<Src, V, Uninit> for Dst
impl<Src, Dst> TransmuteFrom<Src, Valid, Initialized> for Dst
impl<T> TransmuteFrom<Unalign<T>, Valid, Valid> for T
impl<T> TransmuteFrom<UnsafeCell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Wrapping<T>, Valid, Valid> for T
impl<Src, Dst, A, SV, DV, C, R> TransmuteFromPtr<Src, A, SV, DV, C, R> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
C: CastExact<Src, Dst>,
Dst: TransmuteFrom<Src, SV, DV> + TryTransmuteFromPtr<Src, A, SV, DV, C, R> + ?Sized,
Src: ?Sized,
impl<Src, Dst, SV, DV, A, C, R> TryTransmuteFromPtr<Src, A, SV, DV, C, (BecauseMutationCompatible, R)> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
Dst: MutationCompatible<Src, A, SV, DV, R> + ?Sized,
C: CastExact<Src, Dst>,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 16 bytes