2 个版本
0.1.1 | 2024 年 6 月 8 日 |
---|---|
0.1.0 | 2024 年 2 月 18 日 |
#459 in WebAssembly
17KB
155 行
在 Web 上处理定时器:`setTimeout` 和 `setInterval`。
这些 API 有两种形式
- 回调风格(更直接地模仿 JavaScript API),以及
Future
和Stream
API。
超时
超时在经过一段时间(以毫秒为单位)后触发一次。
带有回调函数的超时
use ianaio_timers::callback::Timeout;
let timeout = Timeout::new(1_000, move || {
// Do something after the one second timeout is up!
});
// Since we don't plan on cancelling the timeout, call `forget`.
timeout.forget();
作为 Future
的超时
启用 futures
功能后,将暴露一个包含基于 futures 的定时器的 future
模块。
依赖项
~1–1.7MB
~31K SLoC