pub struct SingleThreadExecutor { /* private fields */ }
Expand description
An executor implementation backed by a single thread.
Unfortunately, in order to maintain a 100% “safe” codebase, it can only accept futures with a
lifetime of ['static
]. The CurrentThreadExecutor
does not have this limitation.
This actually uses a CurrentThreadExecutor
wrapped in a single thread.
This executor will run all tasks to completion, even when dropped.
Implementations§
Source§impl SingleThreadExecutor
impl SingleThreadExecutor
Sourcepub fn new() -> SingleThreadExecutor
pub fn new() -> SingleThreadExecutor
Creates a new SingleThreadExecutor
and spawns a new thread to back it. The thread
immediately starts attempting to execute jobs.
The queue is an unlimited queue, and will happily accept as many jobs as you can pass to it.
Sourcepub fn submit<T: Send + 'static, F: Future<Output = T> + Send + 'static>(
&mut self,
fut: F,
) -> Result<TaskHandle<T>, TaskError>
pub fn submit<T: Send + 'static, F: Future<Output = T> + Send + 'static>( &mut self, fut: F, ) -> Result<TaskHandle<T>, TaskError>
Submits a new task to be run on this executor. The task will start to be run as soon as the executor has available capacity to run it.
This function returns a TaskHandle
that can be used to retrieve any return
result from the operation itself.
Sourcepub fn run_until_complete(self)
pub fn run_until_complete(self)
Runs this executor until all tasks are complete.
Trait Implementations§
Source§impl Default for SingleThreadExecutor
Same as SingleThreadExecutor::new
impl Default for SingleThreadExecutor
Same as SingleThreadExecutor::new
Source§fn default() -> Self
fn default() -> Self
Same as SingleThreadExecutor::new