[][src]Trait scoped_spawn::ScopedSpawn

pub trait ScopedSpawn: Clone + Send + Sync {
    type CancelSender: ForgettableSignalSender + Send;
    type DoneReceiver: SignalReceiver + Send;
    type FutureCancelSender: ForgettableSignalSender + Send;
    type FutureDoneReceiver: SignalReceiver + Send;
    type Raw: RawScopedSpawn;
    fn spawn<Fut, Fun, Done>(
        &self,
        fun: Fun,
        done: Done
    ) -> Result<(), SpawnError>
    where
        Fut: Future<Output = ()> + Send + 'static,
        Fun: FnOnce(Self) -> Fut,
        Done: FnOnce() + Send + 'static
;
fn spawn_with_signal<Fut, Fun, Done>(
        &self,
        fun: Fun,
        done: Done
    ) -> Result<ParentSignals<Self::CancelSender, Self::DoneReceiver>, SpawnError>
    where
        Fut: Future<Output = ()> + Send + 'static,
        Fun: FnOnce(Self) -> Fut,
        Done: FnOnce() + Send + 'static
;
fn spawn_future<Fut, Done>(
        &self,
        fut: Fut,
        done: Done
    ) -> Result<(), SpawnError>
    where
        Fut: Future<Output = ()> + Send + 'static,
        Done: FnOnce() + Send + 'static
;
fn spawn_future_with_signal<Fut, Done>(
        &self,
        fut: Fut,
        done: Done
    ) -> Result<ParentSignals<Self::FutureCancelSender, Self::FutureDoneReceiver>, SpawnError>
    where
        Fut: Future<Output = ()> + Send + 'static,
        Done: FnOnce() + Send + 'static
;
fn as_raw(&self) -> &Self::Raw;
fn into_raw(self) -> Self::Raw; }

Allows for spawning tasks in a scope. Implementors should provide structured concurrency.

Spawning a task

When spawning a task, you can choose to allow the spawned task to spawn more tasks on its own. In this case, use spawn and spawn_with_signal, whose input is a function that takes a spawner for the child task and returns a future. If you do not need a spawner for the child task, use spawn_future and spawn_future_with_signal, in which case the spawned object is only a future.

Associated Types

type CancelSender: ForgettableSignalSender + Send

The type of the signal sender for parents to initiate task termination.

type DoneReceiver: SignalReceiver + Send

The type of the signal receiver for parents to wait for task termination.

type FutureCancelSender: ForgettableSignalSender + Send

The type of the signal sender for parents to initiate task termination, when the spawned object is only a future.

type FutureDoneReceiver: SignalReceiver + Send

The type of the signal receiver for parents to wait for task termination, when the spawned object is only a future.

type Raw: RawScopedSpawn

The type of the raw spawner.

Loading content...

Required methods

fn spawn<Fut, Fun, Done>(&self, fun: Fun, done: Done) -> Result<(), SpawnError> where
    Fut: Future<Output = ()> + Send + 'static,
    Fun: FnOnce(Self) -> Fut,
    Done: FnOnce() + Send + 'static, 

Spawns a task to run the future returned by fun. The spawned task will call done after all its children terminate.

fn spawn_with_signal<Fut, Fun, Done>(
    &self,
    fun: Fun,
    done: Done
) -> Result<ParentSignals<Self::CancelSender, Self::DoneReceiver>, SpawnError> where
    Fut: Future<Output = ()> + Send + 'static,
    Fun: FnOnce(Self) -> Fut,
    Done: FnOnce() + Send + 'static, 

Spawns a task to run the future returned by fun. The spawned task will call done after all its children terminate.

The ParentSignals returned by this method can be used to cancel the task and wait for task termination.

fn spawn_future<Fut, Done>(
    &self,
    fut: Fut,
    done: Done
) -> Result<(), SpawnError> where
    Fut: Future<Output = ()> + Send + 'static,
    Done: FnOnce() + Send + 'static, 

Spawns a task to run fut. The spawned task will call done after all its children terminate.

fn spawn_future_with_signal<Fut, Done>(
    &self,
    fut: Fut,
    done: Done
) -> Result<ParentSignals<Self::FutureCancelSender, Self::FutureDoneReceiver>, SpawnError> where
    Fut: Future<Output = ()> + Send + 'static,
    Done: FnOnce() + Send + 'static, 

Spawns a task to run fut. The spawned task will call done after all its children terminate.

The ParentSignals returned by this method can be used to cancel the task and wait for task termination.

fn as_raw(&self) -> &Self::Raw

Returns a reference to the raw spawner.

fn into_raw(self) -> Self::Raw

Converts self into the raw spawner.

Loading content...

Implementors

impl<Spawn: Spawn + Clone + Send + Sync> ScopedSpawn for ScopedSpawner<Spawn>[src]

type CancelSender = RemoteCancelSenderWithSignal

type DoneReceiver = RemoteDoneReceiverWithSignal

type FutureCancelSender = RemoteCancelSenderWithSignal

type FutureDoneReceiver = RemoteDoneReceiverWithSignal

type Raw = RemoteSpawner

Loading content...