pub trait Executor {
Show 18 methods
// Required method
fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
where F: Future + Send + 'static,
F::Output: Send + 'static;
// Provided methods
fn runtime_type(&self) -> Option<&'static str> { ... }
fn spawn_abortable<F>(&self, future: F) -> AbortableJoinHandle<F::Output> ⓘ
where F: Future + Send + 'static,
F::Output: Send + 'static { ... }
fn dispatch<F>(&self, future: F)
where F: Future + Send + 'static,
F::Output: Send + 'static { ... }
fn spawn_coroutine<T, F, Fut>(&self, f: F) -> CommunicationTask<T>
where F: FnMut(T) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send + 'static,
T: Send + 'static { ... }
fn spawn_coroutine_with_buffer<T, F, Fut>(
&self,
buffer: usize,
f: F,
) -> CommunicationTask<T>
where F: FnMut(T) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send + 'static,
T: Send + 'static { ... }
fn spawn_unbounded_coroutine<T, F, Fut>(
&self,
f: F,
) -> UnboundedCommunicationTask<T>
where F: FnMut(T) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send + 'static,
T: Send + 'static { ... }
fn spawn_coroutine_with_context<T, C, F, Fut>(
&self,
context: C,
f: F,
) -> CommunicationTask<T>
where F: FnMut(&mut C, T) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send + 'static,
C: Send + 'static,
T: Send + 'static { ... }
fn spawn_coroutine_with_buffer_and_context<T, C, F, Fut>(
&self,
context: C,
buffer: usize,
f: F,
) -> CommunicationTask<T>
where F: FnMut(&mut C, T) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send + 'static,
C: Send + 'static,
T: Send + 'static { ... }
fn spawn_unbounded_coroutine_with_context<T, C, F, Fut>(
&self,
context: C,
f: F,
) -> UnboundedCommunicationTask<T>
where F: FnMut(&mut C, T) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send + 'static,
C: Send + 'static,
T: Send + 'static { ... }
fn spawn_coroutine_with_receiver<T, F, Fut>(
&self,
f: F,
) -> CommunicationTask<T>
where F: FnMut(Receiver<T>) -> Fut,
Fut: Future<Output = ()> + Send + 'static { ... }
fn spawn_coroutine_with_receiver_and_buffer<T, F, Fut>(
&self,
buffer: usize,
f: F,
) -> CommunicationTask<T>
where F: FnMut(Receiver<T>) -> Fut,
Fut: Future<Output = ()> + Send + 'static { ... }
fn spawn_coroutine_with_receiver_and_context<T, F, C, Fut>(
&self,
context: C,
f: F,
) -> CommunicationTask<T>
where F: FnMut(C, Receiver<T>) -> Fut,
Fut: Future<Output = ()> + Send + 'static { ... }
fn spawn_coroutine_with_receiver_buffer_and_context<T, F, C, Fut>(
&self,
context: C,
buffer: usize,
f: F,
) -> CommunicationTask<T>
where F: FnMut(C, Receiver<T>) -> Fut,
Fut: Future<Output = ()> + Send + 'static { ... }
fn spawn_unbounded_coroutine_with_receiver<T, F, Fut>(
&self,
f: F,
) -> UnboundedCommunicationTask<T>
where F: FnMut(UnboundedReceiver<T>) -> Fut,
Fut: Future<Output = ()> + Send + 'static { ... }
fn spawn_unbounded_coroutine_with_receiver_and_context<T, F, C, Fut>(
&self,
context: C,
f: F,
) -> UnboundedCommunicationTask<T>
where F: FnMut(C, UnboundedReceiver<T>) -> Fut,
Fut: Future<Output = ()> + Send + 'static { ... }
fn scope<'env, F, T>(&self, f: F) -> impl Future<Output = T>
where F: for<'scope> AsyncFnOnce(&'scope Scope<'scope, 'env>) -> T { ... }
fn executor_scope<'scope, F, T>(
&'scope self,
f: F,
) -> impl Future<Output = T>
where Self: Sized,
F: AsyncFnOnce(&ScopeExecutor<'scope, Self>) -> T { ... }
}Required Methods§
Sourcefn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
Spawns a new asynchronous task in the background, returning a Future JoinHandle for it.
Provided Methods§
Sourcefn runtime_type(&self) -> Option<&'static str>
fn runtime_type(&self) -> Option<&'static str>
Returns an optional runtime name of the executor.
Sourcefn spawn_abortable<F>(&self, future: F) -> AbortableJoinHandle<F::Output> ⓘ
fn spawn_abortable<F>(&self, future: F) -> AbortableJoinHandle<F::Output> ⓘ
Spawns a new asynchronous task in the background, returning an abortable handle that will cancel the task once the handle is dropped.
Note: This function is used if the task is expected to run until the handle is dropped. It is recommended to use
Executor::spawn or Executor::dispatch otherwise.
Sourcefn dispatch<F>(&self, future: F)
fn dispatch<F>(&self, future: F)
Spawns a new asynchronous task in the background without an handle.
Basically the same as Executor::spawn.
Sourcefn spawn_coroutine<T, F, Fut>(&self, f: F) -> CommunicationTask<T>
fn spawn_coroutine<T, F, Fut>(&self, f: F) -> CommunicationTask<T>
Spawns a new asynchronous task that accepts messages to the task. This function returns a handle that allows sending a message, or if there is no reference to the handle at all (in other words, all handles are dropped), the task would be aborted.
Sourcefn spawn_coroutine_with_buffer<T, F, Fut>(
&self,
buffer: usize,
f: F,
) -> CommunicationTask<T>
fn spawn_coroutine_with_buffer<T, F, Fut>( &self, buffer: usize, f: F, ) -> CommunicationTask<T>
Spawns a new asynchronous task that accepts messages to the task with a set buffer. This function returns a handle that allows sending a message, or if there is no reference to the handle at all (in other words, all handles are dropped), the task would be aborted.
Sourcefn spawn_unbounded_coroutine<T, F, Fut>(
&self,
f: F,
) -> UnboundedCommunicationTask<T>
fn spawn_unbounded_coroutine<T, F, Fut>( &self, f: F, ) -> UnboundedCommunicationTask<T>
Spawns a new asynchronous task that accepts unbounded messages to the task. This function returns a handle that allows sending a message, or if there is no reference to the handle at all (in other words, all handles are dropped), the task would be aborted.
Sourcefn spawn_coroutine_with_context<T, C, F, Fut>(
&self,
context: C,
f: F,
) -> CommunicationTask<T>
fn spawn_coroutine_with_context<T, C, F, Fut>( &self, context: C, f: F, ) -> CommunicationTask<T>
Spawns a new asynchronous task with provided context that accepts messages to the task. This function returns a handle that allows sending a message, or if there is no reference to the handle at all (in other words, all handles are dropped), the task would be aborted.
§Note
If state must be borrowed across awaits,
use Executor::spawn_coroutine_with_receiver_and_context.
Sourcefn spawn_coroutine_with_buffer_and_context<T, C, F, Fut>(
&self,
context: C,
buffer: usize,
f: F,
) -> CommunicationTask<T>
fn spawn_coroutine_with_buffer_and_context<T, C, F, Fut>( &self, context: C, buffer: usize, f: F, ) -> CommunicationTask<T>
Spawns a new asynchronous task with provided context that accepts messages to the task with a set buffer. This function returns a handle that allows sending a message, or if there is no reference to the handle at all (in other words, all handles are dropped), the task would be aborted.
Sourcefn spawn_unbounded_coroutine_with_context<T, C, F, Fut>(
&self,
context: C,
f: F,
) -> UnboundedCommunicationTask<T>
fn spawn_unbounded_coroutine_with_context<T, C, F, Fut>( &self, context: C, f: F, ) -> UnboundedCommunicationTask<T>
Spawns a new asynchronous task with provided context that accepts unbounded messages to the task. This function returns a handle that allows sending a message, or if there is no reference to the handle at all (in other words, all handles are dropped), the task would be aborted.
Sourcefn spawn_coroutine_with_receiver<T, F, Fut>(&self, f: F) -> CommunicationTask<T>
fn spawn_coroutine_with_receiver<T, F, Fut>(&self, f: F) -> CommunicationTask<T>
Spawns a new asynchronous task that accepts messages to the task using channels.
This function returns a handle that allows sending a message, or if there is no reference to the handle at all
(in other words, all handles are dropped), the task would be aborted.
Sourcefn spawn_coroutine_with_receiver_and_buffer<T, F, Fut>(
&self,
buffer: usize,
f: F,
) -> CommunicationTask<T>
fn spawn_coroutine_with_receiver_and_buffer<T, F, Fut>( &self, buffer: usize, f: F, ) -> CommunicationTask<T>
Spawns a new asynchronous task with a set channel buffer that accepts messages to the task using channels.
This function returns a handle that allows sending a message, or if there is no reference to the handle at all
(in other words, all handles are dropped), the task would be aborted.
Sourcefn spawn_coroutine_with_receiver_and_context<T, F, C, Fut>(
&self,
context: C,
f: F,
) -> CommunicationTask<T>
fn spawn_coroutine_with_receiver_and_context<T, F, C, Fut>( &self, context: C, f: F, ) -> CommunicationTask<T>
Spawns a new asynchronous task with provided context that accepts messages to the task using channels.
This function returns a handle that allows sending a message, or if there is no reference to the handle at all
(in other words, all handles are dropped), the task would be aborted.
Sourcefn spawn_coroutine_with_receiver_buffer_and_context<T, F, C, Fut>(
&self,
context: C,
buffer: usize,
f: F,
) -> CommunicationTask<T>
fn spawn_coroutine_with_receiver_buffer_and_context<T, F, C, Fut>( &self, context: C, buffer: usize, f: F, ) -> CommunicationTask<T>
Spawns a new asynchronous task with a set channel buffer and provided context that accepts messages to the task using channels.
This function returns a handle that allows sending a message, or if there is no reference to the handle at all
(in other words, all handles are dropped), the task would be aborted.
Sourcefn spawn_unbounded_coroutine_with_receiver<T, F, Fut>(
&self,
f: F,
) -> UnboundedCommunicationTask<T>
fn spawn_unbounded_coroutine_with_receiver<T, F, Fut>( &self, f: F, ) -> UnboundedCommunicationTask<T>
Spawns a new asynchronous task that accepts messages to the task using channels.
This function returns a handle that allows sending a message, or if there is no reference to the handle at all
(in other words, all handles are dropped), the task would be aborted.
Sourcefn spawn_unbounded_coroutine_with_receiver_and_context<T, F, C, Fut>(
&self,
context: C,
f: F,
) -> UnboundedCommunicationTask<T>
fn spawn_unbounded_coroutine_with_receiver_and_context<T, F, C, Fut>( &self, context: C, f: F, ) -> UnboundedCommunicationTask<T>
Spawns a new asynchronous task with provided context that accepts messages to the task using channels.
This function returns a handle that allows sending a message, or if there is no reference to the handle at all
(in other words, all handles are dropped), the task would be aborted.
Sourcefn scope<'env, F, T>(&self, f: F) -> impl Future<Output = T>where
F: for<'scope> AsyncFnOnce(&'scope Scope<'scope, 'env>) -> T,
fn scope<'env, F, T>(&self, f: F) -> impl Future<Output = T>where
F: for<'scope> AsyncFnOnce(&'scope Scope<'scope, 'env>) -> T,
Create a structured-concurrency scope in which tasks may be spawned that borrow from the enclosing stack frame.
Unlike Executor::spawn, tasks spawned on the Scope are driven
cooperatively by the returned future so they may borrow any data that outlives
the 'env lifetime. Every task is either completed or canceled before
scope returns, so borrows never outlive the stack frame.
This is the async analogue of std::thread::scope.
§Example
use async_rt::Executor;
use async_rt::global::ConfiguredExecutor;
let executor: ConfiguredExecutor = ConfiguredExecutor::default();
let data = vec![1, 2, 3, 4];
let sum = executor
.scope(async |s| {
let a = s.spawn(async { data[0] + data[1] });
let b = s.spawn(async { data[2] + data[3] });
a.await.unwrap() + b.await.unwrap()
})
.await;
assert_eq!(sum, 10);Sourcefn executor_scope<'scope, F, T>(&'scope self, f: F) -> impl Future<Output = T>
fn executor_scope<'scope, F, T>(&'scope self, f: F) -> impl Future<Output = T>
Run an async closure with a scoped Executor wrapper that
forwards spawns to this executor, waits for all spawned tasks
to finish when the closure returns, and aborts any outstanding
tasks if the scope future itself is cancelled.
Unlike Executor::scope, tasks run on the real executor (so
they get real parallelism) but must be Send + 'static.
§Example
use async_rt::Executor;
use async_rt::global::ConfiguredExecutor;
let executor: ConfiguredExecutor = ConfiguredExecutor::default();
let total = executor
.executor_scope(async |s| {
let a = s.spawn(async { 1 + 2 });
let b = s.spawn(async { 3 + 4 });
a.await.unwrap() + b.await.unwrap()
})
.await;
assert_eq!(total, 10);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".