pub struct WorkerPool { /* private fields */ }Expand description
Fixed-size thread pool with bounded FIFO task queue.
zshrs-original — replaces C zsh’s per-task fork() + wait()
pattern (Src/exec.c zfork() / Src/jobs.c child management) with
a persistent thread pool. Uses crossbeam-channel for lock-free
multi-consumer dispatch — each worker calls recv() directly,
no mutex.
Implementations§
Source§impl WorkerPool
impl WorkerPool
Sourcepub fn new(size: usize) -> Self
pub fn new(size: usize) -> Self
Create a pool with size worker threads and bounded channel.
Channel capacity = 4 × size (provides backpressure without
starving).
zshrs-original — no C counterpart. Replaces the
“spawn-on-demand” semantics of zfork() (Src/exec.c) with
pre-spawned threads ready to receive work over a bounded
channel.
Sourcepub fn default_size() -> Self
pub fn default_size() -> Self
Create a pool sized to the machine’s parallelism, clamped to
[2, 18].
zshrs-original — no C counterpart. C zsh has no concept of a
“pool size” because it forks on demand (one child per
background task, see Src/jobs.c).
Sourcepub fn submit<F>(&self, f: F)
pub fn submit<F>(&self, f: F)
Submit a task to the pool. Blocks if the queue is full
(backpressure). Panics if the pool has been shut down.
zshrs-original — replaces the fork() + execve() /
fork() + run-shell-fn dispatch pairs in Src/exec.c.
Sourcepub fn submit_with_result<F, R>(&self, f: F) -> Receiver<R>
pub fn submit_with_result<F, R>(&self, f: F) -> Receiver<R>
Submit a task and get a receiver for its result.
zshrs-original — closest C analog is the pipe-based
command-substitution result capture in Src/exec.c
(getoutput() reading the child’s stdout pipe), but using a
typed Rust channel sidesteps the marshalling.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Signal all workers to drop pending tasks.
Already-running tasks will finish, but queued tasks are
skipped. Reset with reset_cancel().
zshrs-original — closest C analog is the SIGINT/SIGQUIT
signal-storm dispatch C zsh fires at its background children
in Src/signals.c (killjb() / killpg()), but here we set a
flag instead of sending a signal across a fork boundary.
Sourcepub fn reset_cancel(&self)
pub fn reset_cancel(&self)
Clear the cancellation flag — pool resumes normal execution. zshrs-original — no C counterpart.
Sourcepub fn queue_depth(&self) -> usize
pub fn queue_depth(&self) -> usize
Approximate number of tasks waiting in the queue.
zshrs-original — no C counterpart; closest equivalent is the
jobtab length walk Src/jobs.c uses for jobs -l output.
Trait Implementations§
Source§impl Drop for WorkerPool
impl Drop for WorkerPool
Auto Trait Implementations§
impl Freeze for WorkerPool
impl !RefUnwindSafe for WorkerPool
impl Send for WorkerPool
impl Sync for WorkerPool
impl Unpin for WorkerPool
impl UnsafeUnpin for WorkerPool
impl !UnwindSafe for WorkerPool
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more