Crate smolscale[−][src]
Expand description
A global, auto-scaling, preemptive scheduler based on async-executor
.
smolscale
is a fairly thin wrapper around a global [async-executor
]. Unlike async-global-executor
and friends, however, it has a preemptive thread pool that ensures that tasks cannot block other tasks no matter what. This means that you can do things like run expensive computations or even do blocking I/O within a task without worrying about causing deadlocks. Even with “traditional” tasks that do not block, this approach can reduce worst-case latency.
Furthermore, the thread pool is adaptive, using the least amount of threads required to “get the job done”. This minimizes OS-level context switching, increasing performance in I/O bound tasks compared to the usual approach of spawning OS threads matching the number of CPUs.
Finally, this crate has seriously minimal dependencies, and will not add significantly to your compilation times.
This crate is heavily inspired by Stjepan Glavina’s previous work on async-std.
smolscale
also includes Nursery
, a helper for structured concurrency on the smolscale
global executor.
Structs
Executor | A self-contained executor context. |
Nursery | A nursery represents a dynamic scope in which tasks can be spawned. It is used for structured concurrency, and it ensures that tasks spawned within the nursery terminate before the nursery falls out of scope. |
NurseryHandle | |
Worker |
Enums
OnError | The strategy used to recover from errors that a task returns. |
Functions
active_task_count | Returns the current number of active tasks. |
block_on | Spawns a future onto the global executor and immediately blocks on it. |
permanently_single_threaded | Irrevocably puts smolscale into single-threaded mode. |
running_task_count | Returns the current number of running tasks. |
spawn | Spawns a task onto the lazily-initialized global executor. |