pub struct Scope<'scope, 'env: 'scope> { /* private fields */ }Expand description
A scope within which tasks can be spawned that borrow from the enclosing stack frame.
Implementations§
Source§impl<'scope, 'env> Scope<'scope, 'env>
impl<'scope, 'env> Scope<'scope, 'env>
Sourcepub fn spawn<Fut>(&'scope self, fut: Fut) -> ScopedJoinHandle<Fut::Output> ⓘ
pub fn spawn<Fut>(&'scope self, fut: Fut) -> ScopedJoinHandle<Fut::Output> ⓘ
Spawn a task into this scope.
The future may borrow any data that outlives its lifetime 'env. The task will
be polled cooperatively alongside the scope’s user closure and any
other spawned tasks.
Sourcepub fn spawn_abortable<Fut>(
&'scope self,
fut: Fut,
) -> AbortableJoinHandle<Fut::Output> ⓘ
pub fn spawn_abortable<Fut>( &'scope self, fut: Fut, ) -> AbortableJoinHandle<Fut::Output> ⓘ
Spawn a task into this scope and return an AbortableJoinHandle.
This mirrors Executor::spawn_abortable for cooperatively
scheduled tasks. The returned handle aborts the task when all
references to it have been dropped.
Sourcepub fn dispatch<Fut>(&'scope self, fut: Fut)
pub fn dispatch<Fut>(&'scope self, fut: Fut)
Spawn a task into this scope without keeping a handle to it.
Equivalent to Executor::dispatch for scoped tasks.
Sourcepub fn spawn_coroutine<T, F, Fut>(&'scope self, f: F) -> CommunicationTask<T>
pub fn spawn_coroutine<T, F, Fut>(&'scope self, f: F) -> CommunicationTask<T>
Spawn a message-driven coroutine into this scope.
Equivalent to Executor::spawn_coroutine for scoped tasks.
Sourcepub fn spawn_coroutine_with_buffer<T, F, Fut>(
&'scope self,
buffer: usize,
f: F,
) -> CommunicationTask<T>
pub fn spawn_coroutine_with_buffer<T, F, Fut>( &'scope self, buffer: usize, f: F, ) -> CommunicationTask<T>
Like Scope::spawn_coroutine but with a configurable channel
buffer.
Sourcepub fn spawn_unbounded_coroutine<T, F, Fut>(
&'scope self,
f: F,
) -> UnboundedCommunicationTask<T>
pub fn spawn_unbounded_coroutine<T, F, Fut>( &'scope self, f: F, ) -> UnboundedCommunicationTask<T>
Spawn an unbounded message-driven coroutine into this scope.
Equivalent to Executor::spawn_unbounded_coroutine for scoped
tasks.
Sourcepub fn spawn_coroutine_with_context<T, C, F, Fut>(
&'scope self,
context: C,
f: F,
) -> CommunicationTask<T>
pub fn spawn_coroutine_with_context<T, C, F, Fut>( &'scope self, context: C, f: F, ) -> CommunicationTask<T>
Spawn a message-driven coroutine with caller-provided context.
If the context must be borrowed across awaits, use
Scope::spawn_coroutine_with_receiver_and_context.
Sourcepub fn spawn_coroutine_with_buffer_and_context<T, C, F, Fut>(
&'scope self,
context: C,
buffer: usize,
f: F,
) -> CommunicationTask<T>
pub fn spawn_coroutine_with_buffer_and_context<T, C, F, Fut>( &'scope self, context: C, buffer: usize, f: F, ) -> CommunicationTask<T>
Like Scope::spawn_coroutine_with_context but with a configurable
channel buffer.
Sourcepub fn spawn_unbounded_coroutine_with_context<T, C, F, Fut>(
&'scope self,
context: C,
f: F,
) -> UnboundedCommunicationTask<T>
pub fn spawn_unbounded_coroutine_with_context<T, C, F, Fut>( &'scope self, context: C, f: F, ) -> UnboundedCommunicationTask<T>
Spawn an unbounded message-driven coroutine with caller-provided context.
Sourcepub fn spawn_coroutine_with_receiver<T, F, Fut>(
&'scope self,
f: F,
) -> CommunicationTask<T>
pub fn spawn_coroutine_with_receiver<T, F, Fut>( &'scope self, f: F, ) -> CommunicationTask<T>
Spawn a coroutine that receives the bounded channel directly.
Sourcepub fn spawn_coroutine_with_receiver_and_buffer<T, F, Fut>(
&'scope self,
buffer: usize,
f: F,
) -> CommunicationTask<T>
pub fn spawn_coroutine_with_receiver_and_buffer<T, F, Fut>( &'scope self, buffer: usize, f: F, ) -> CommunicationTask<T>
Like Scope::spawn_coroutine_with_receiver but with a configurable
channel buffer.
Sourcepub fn spawn_coroutine_with_receiver_and_context<T, F, C, Fut>(
&'scope self,
context: C,
f: F,
) -> CommunicationTask<T>
pub fn spawn_coroutine_with_receiver_and_context<T, F, C, Fut>( &'scope self, context: C, f: F, ) -> CommunicationTask<T>
Spawn a coroutine that receives caller-provided context and the bounded channel directly.
Sourcepub fn spawn_coroutine_with_receiver_buffer_and_context<T, F, C, Fut>(
&'scope self,
context: C,
buffer: usize,
f: F,
) -> CommunicationTask<T>
pub fn spawn_coroutine_with_receiver_buffer_and_context<T, F, C, Fut>( &'scope self, context: C, buffer: usize, f: F, ) -> CommunicationTask<T>
Like Scope::spawn_coroutine_with_receiver_and_context but with a
configurable channel buffer.
Sourcepub fn spawn_unbounded_coroutine_with_receiver<T, F, Fut>(
&'scope self,
f: F,
) -> UnboundedCommunicationTask<T>
pub fn spawn_unbounded_coroutine_with_receiver<T, F, Fut>( &'scope self, f: F, ) -> UnboundedCommunicationTask<T>
Spawn a coroutine that receives the unbounded channel directly.
Sourcepub fn spawn_unbounded_coroutine_with_receiver_and_context<T, F, C, Fut>(
&'scope self,
context: C,
f: F,
) -> UnboundedCommunicationTask<T>
pub fn spawn_unbounded_coroutine_with_receiver_and_context<T, F, C, Fut>( &'scope self, context: C, f: F, ) -> UnboundedCommunicationTask<T>
Spawn a coroutine that receives caller-provided context and the unbounded channel directly.
Sourcepub fn spawn_timeout<F>(
&'scope self,
duration: Duration,
f: F,
) -> ScopedJoinHandle<Result<F::Output, TimeoutError>> ⓘ
pub fn spawn_timeout<F>( &'scope self, duration: Duration, f: F, ) -> ScopedJoinHandle<Result<F::Output, TimeoutError>> ⓘ
Spawn a scoped task that must complete within duration.
If the future does not finish before duration elapses, it is dropped and the task
completes with TimeoutError. This is the scoped analogue of
ExecutorTimeout::spawn_timeout.
Sourcepub fn spawn_delay<F>(
&'scope self,
duration: Duration,
f: F,
) -> ScopedJoinHandle<F::Output> ⓘ
pub fn spawn_delay<F>( &'scope self, duration: Duration, f: F, ) -> ScopedJoinHandle<F::Output> ⓘ
Spawns a task after waiting for a duration before the task is polled.
Sourcepub fn spawn_abortable_timeout<F>(
&'scope self,
duration: Duration,
f: F,
) -> AbortableJoinHandle<Result<F::Output, TimeoutError>> ⓘ
pub fn spawn_abortable_timeout<F>( &'scope self, duration: Duration, f: F, ) -> AbortableJoinHandle<Result<F::Output, TimeoutError>> ⓘ
Spawn a scoped task that must complete within duration, returning an
AbortableJoinHandle that cancels the task once all references to it are dropped.
If the future does not finish before duration elapses, it is dropped and the task
completes with TimeoutError.
Sourcepub fn spawn_abortable_delay<F>(
&'scope self,
duration: Duration,
f: F,
) -> AbortableJoinHandle<F::Output> ⓘ
pub fn spawn_abortable_delay<F>( &'scope self, duration: Duration, f: F, ) -> AbortableJoinHandle<F::Output> ⓘ
Spawns a task after waiting for a duration before the task is polled.