Expand description
Executors allow easy scheduling and execution of functions or closures.
The CoreExecutor
uses a single thread for scheduling and execution, while the
ThreadPoolExecutor
uses multiple threads to execute the function.
Internally, each executor uses a tokio_core::reactor::Core
as event loop, that will drive
the scheduling of the functions (and for the CoreExecutor
, also their execution). A reference
to the event loop is passed to every function when executed, allowing it to register additional
events if needed.
Structs§
- Core
Executor - A
CoreExecutor
is the most simple executor provided. It runs a single thread, which is responsible for both scheduling the function (registering the timer for the wakeup), and the actual execution. The executor will stop once dropped. TheCoreExecutor
can be cloned to generate a new reference to the same underlying executor. Given the single threaded nature of this executor, tasks are executed sequentially, and a long running task will cause delay in other subsequent executions. - Task
Handle - A handle that allows a task to be stopped. A new handle is returned every time a new task is scheduled. Note that stopping a task will prevent it from running the next time it’s scheduled to run, but it won’t interrupt a task that is currently being executed.
- Thread
Pool Executor - A
ThreadPoolExecutor
will use one thread for the task scheduling and a thread pool for task execution, allowing multiple tasks to run in parallel.