Struct xstream_util::Limiting

source ·
pub struct Limiting<C> { /* private fields */ }
Expand description

A pool to manage spawning a limited number of processses

This will wait for the oldest scheduled process to complete before scheduling a new one. If you schedule a long running process, then a bunch of short ones, it won’t schedule more short ones beyond the buffer until the long one has finished.

Implementations§

source§

impl<C: BorrowMut<Command>> Limiting<C>

source

pub fn new(command: C, max_procs: usize) -> Self

Create a new empty pool with a limited number of total processes

Set max_procs to 0 to enable unbounded parallelism.

Trait Implementations§

source§

impl<C: Debug> Debug for Limiting<C>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<C> Drop for Limiting<C>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<C: BorrowMut<Command>> Pool for Limiting<C>

source§

fn get(&mut self) -> Result<&mut Child, Error>

Spawn a new process with command and return a mutable reference to the process

This command will block until it can schedule the process under the constraints. It can fail for any reason, including an earlier process failed, and never actually spawn the process in question. If it does successfully spawn the process, it will be recorded so that it will be cleaned up if the pool is dropped.

source§

fn join(&mut self) -> Result<(), Error>

Wait for all processes to finish

Errors will terminate early and not wait for reamining processes to finish. To continue waiting for them anyway you can continue to call join until you get a success, this will indicate that there are no more running processes under management by the pool.

Auto Trait Implementations§

§

impl<C> RefUnwindSafe for Limiting<C>
where C: RefUnwindSafe,

§

impl<C> Send for Limiting<C>
where C: Send,

§

impl<C> Sync for Limiting<C>
where C: Sync,

§

impl<C> Unpin for Limiting<C>
where C: Unpin,

§

impl<C> UnwindSafe for Limiting<C>
where C: UnwindSafe,

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>,

§

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>,

§

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.