2.4.1 Tokio
01-Tokio — Comprehensive Rust
1分钟内可阅读完
译文 · 基于 Comprehensive Rust
原文链接: https://google.github.io/comprehensive-rust/concurrency/async/runtimes.html
运行时(runtime)提供异步执行操作的支持(reactor),并负责执行 futures(executor)。Rust 没有「内置」运行时,但有多种可选方案:
一些更大的应用有自己的运行时。例如 Fuchsia 已有一个。
注意:所列运行时中,只有 Tokio 在 Rust playground 中受支持。playground 也不允许任何 I/O,因此多数有趣的异步内容无法在 playground 中运行。
Future 是「惰性」的:除非有 executor 轮询它们,否则它们什么也不做(甚至不会启动 I/O 操作)。这与 JS Promise 不同——例如即使从未使用,Promise 也会运行到完成。
01-Tokio — Comprehensive Rust