Module tokio::executor::current_thread
[−]
[src]
Execute tasks on the current thread
This module implements an executor that keeps futures on the same thread
that they are submitted on. This allows it to execute futures that are
not Send
.
Before being able to spawn futures with this module, an executor
context must be setup by calling run
. From within that context spawn
may be called with the future to run in the background.
use futures::future::lazy; // Calling execute here results in a panic // current_thread::spawn(my_future); current_thread::run(|_| { // The execution context is setup, futures may be executed. current_thread::spawn(lazy(|| { println!("called from the current thread executor"); Ok(()) })); });
Execution model
When an execution context is setup with run
the current thread will block
and all the futures managed by the executor are driven to completion.
Whenever a future receives a notification, it is pushed to the end of a
scheduled list. The executor will drain this list, advancing the state of
each future.
All futures managed by this module will remain on the current thread,
as such, this module is able to safely execute futures that are not Send
.
Once a future is complete, it is dropped. Once all futures are completed,
run
will unblock and return.
This module makes a best effort to fairly schedule futures that it manages.
Structs
Context |
A context yielded to the closure provided to |
TaskExecutor |
Executes futures on the current thread. |
Functions
run |
Calls the given closure, then block until all futures submitted for execution complete. |
run_with_sleep |
Calls the given closure with a custom sleep strategy. |
spawn |
Executes a future on the current thread. |
task_executor |
Returns an executor that executes futures on the current thread. |