Yew中使用wasm_timer重复执行回调
我对 Rust 还很陌生,很难理解 future。我想在浏览器中实现一个“计时器应用程序”,为此我使用 https://yew.rs/< /a>.对于计时器,我尝试使用 https://github.com/tomaka/wasm-timer/,但没有文档,也没有示例。看起来用法应该很明显,但我不明白。
我假设我必须做类似的事情:
let i = Interval::new(core::time::Duration::from_millis(250));
这应该创建一个每 250 毫秒触发一次的间隔。但什么被解雇了呢?如何指定我的回调?我希望得到这样的结果:
i.somehow_specify_callback(|| { ... executed every 250ms ...});
我的感觉是,我不知何故走在错误的道路上,没有掌握 Rust 期货。非常感谢有关如何使 Interval
执行某些代码的工作示例。
I'm still rather new to Rust and have a hard time wrapping my head around futures. I want to implement a "timer app" in the browser and to do so I'm using https://yew.rs/. For the timer I tried to use https://github.com/tomaka/wasm-timer/, but there are not docs and no examples. Looks like the usage is supposed to be obvious, but I don't get it.
I assume that I have to do something like:
let i = Interval::new(core::time::Duration::from_millis(250));
This should create an Interval that fires every 250ms. But what is fired? How to I specify my callback? I would expect something like:
i.somehow_specify_callback(|| { ... executed every 250ms ...});
My feeling is, that I'm somehow on the wrong path and do not get grasp Rust futures. A working example on how to make an Interval
execute some code would be very appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是计时器组件的伪代码示例:
要了解有关我在代码中使用的挂钩的更多信息,请访问
Here is a pseudo code example for Timer component:
to learn more about the hooks i used in the code visit https://yew.rs/docs/concepts/function-components/hooks#pre-defined-hooks