Spawn

Trait Spawn 

Source
pub trait Spawn<E: ?Sized> {
    type Error;

    // Required method
    fn spawn<'life0, 'life1, 'async_trait>(
        &'life0 self,
        env: &'life1 mut E,
    ) -> Pin<Box<dyn Future<Output = Result<BoxFuture<'static, ExitStatus>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

A trait for spawning commands.

Spawning a command is separated into two distinct parts: a future that requires a mutable environment to make progress, and a future which no longer needs any context and can make progress on its own.

This distinction allows a caller to drop an environment as soon as it is no longer needed, which will free up resources, and especially important in preventing deadlocks between pipelines (since the parent process will contain extra reader/writer ends of a pipe and may prevent processes from exiting).

Required Associated Types§

Source

type Error

The type of error that can arise if there is an error during spawning.

Required Methods§

Source

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> Pin<Box<dyn Future<Output = Result<BoxFuture<'static, ExitStatus>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Spawn the command as a future which returns another future.

The first, or “outer” future returned is allowed to maintain references to both the type being spawned, and the environment itself. Once the command no longer needs a reference to the environment or any other data, it should return a second future which represents the final result of the command.

This separation allows the caller (or poller) to drop the environment as son as it is no longer needed, which will free up resources, and especially important in preventing deadlocks between pipelines (since the parent process will contain extra reader/writer ends of a pipe and may prevent processes from exiting).

Although the implementation is free to make any optimizations or pre-computations, there should be no observable side-effects until the very first call to poll or .await on the future. That way a constructed future that was never polled could be dropped without the risk of unintended side effects.

Implementations on Foreign Types§

Source§

impl<'a, T, E> Spawn<E> for &'a T
where T: ?Sized + Spawn<E>, E: ?Sized,

Source§

type Error = <T as Spawn<E>>::Error

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> BoxFuture<'async_trait, Result<BoxFuture<'static, ExitStatus>, Self::Error>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<N, S, C, F, E> Spawn<E> for PipeableCommand<N, S, C, Arc<F>>
where S: Spawn<E>, C: Spawn<E, Error = S::Error>, N: Sync + Clone, F: Spawn<E, Error = S::Error> + Send + Sync + 'static, E: ?Sized + Send + FunctionEnvironment, E::FnName: From<N>, E::Fn: From<Arc<dyn Spawn<E, Error = S::Error> + Send + Sync>>,

Source§

type Error = <S as Spawn<E>>::Error

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> BoxFuture<'async_trait, Result<BoxFuture<'static, ExitStatus>, Self::Error>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<S, E> Spawn<E> for ListableCommand<S>

Source§

type Error = <S as Spawn<E>>::Error

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> BoxFuture<'async_trait, Result<BoxFuture<'static, ExitStatus>, Self::Error>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<S, R, E> Spawn<E> for CompoundCommand<S, R>

Source§

type Error = <S as Spawn<E>>::Error

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> Pin<Box<dyn Future<Output = Result<BoxFuture<'static, ExitStatus>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<T, E> Spawn<E> for Command<T>

Source§

type Error = <T as Spawn<E>>::Error

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> BoxFuture<'async_trait, Result<BoxFuture<'static, ExitStatus>, Self::Error>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<T, E> Spawn<E> for Box<T>
where T: ?Sized + Spawn<E>, E: ?Sized,

Source§

type Error = <T as Spawn<E>>::Error

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> BoxFuture<'async_trait, Result<BoxFuture<'static, ExitStatus>, Self::Error>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<T, E> Spawn<E> for Arc<T>
where T: ?Sized + Spawn<E>, E: ?Sized,

Source§

type Error = <T as Spawn<E>>::Error

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> BoxFuture<'async_trait, Result<BoxFuture<'static, ExitStatus>, Self::Error>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<T, E> Spawn<E> for AndOrList<T>

Source§

type Error = <T as Spawn<E>>::Error

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> BoxFuture<'async_trait, Result<BoxFuture<'static, ExitStatus>, Self::Error>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<T, E> Spawn<E> for AtomicTopLevelCommand<T>

Source§

type Error = RuntimeError

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> BoxFuture<'async_trait, Result<BoxFuture<'static, ExitStatus>, Self::Error>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<V, W, R, E> Spawn<E> for SimpleCommand<V, W, R>

Source§

type Error = <<E as FunctionEnvironment>::Fn as Spawn<E>>::Error

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> Pin<Box<dyn Future<Output = Result<BoxFuture<'static, ExitStatus>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<V, W, S, E> Spawn<E> for CompoundCommandKind<V, W, S>

Source§

type Error = <S as Spawn<E>>::Error

Source§

fn spawn<'life0, 'life1, 'async_trait>( &'life0 self, env: &'life1 mut E, ) -> Pin<Box<dyn Future<Output = Result<BoxFuture<'static, ExitStatus>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§

Source§

impl<'a, S, E> Spawn<E> for SequenceSlice<'a, S>

Source§

type Error = <S as Spawn<E>>::Error