Nio
Nio is a Thread-Per-Core async runtime for Rust.
Task spawning APIs
Nio uses multiple worker threads to execute tasks.
| Function | Send requirement |
Thread affinity |
|---|---|---|
nio::spawn_local |
!Send allowed |
Pinned to current thread |
nio::spawn_pinned |
Only captured variables | Pinned to one worker thread (selected by the runtime based on load) |
nio::spawn_pinned_at |
Only captured variables | Pinned to a specific worker thread (by index) |
nio::spawn |
Send required |
Not pinned, may move between threads at .await points |
Note: nio::spawn_pinned, nio::spawn_pinned_at accept async closure, Only captured variables required to be Send, task itself is !Send.
Example
[]
= { = "0.1.3", = ["tokio-io"] }
By default, Nio implements async traits from futures-io. But the optional "tokio-io" feature implements async traits from tokio::io.
Here is a basic echo server example:
use AsyncWriteExt;
use TcpListener;
use Result;
async