Skip to main content

WorkerPool

Struct WorkerPool 

Source
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

Source

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.

Source

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).

Source

pub fn submit<F>(&self, f: F)
where F: FnOnce() + Send + 'static,

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.

Source

pub fn submit_with_result<F, R>(&self, f: F) -> Receiver<R>
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

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.

Source

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.

Source

pub fn reset_cancel(&self)

Clear the cancellation flag — pool resumes normal execution. zshrs-original — no C counterpart.

Source

pub fn size(&self) -> usize

Number of worker threads. zshrs-original — no C counterpart.

Source

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.

Source

pub fn completed(&self) -> usize

Total tasks completed since pool creation. zshrs-original — no C counterpart.

Trait Implementations§

Source§

impl Drop for WorkerPool

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,