denoland / denoland/roll-your-own-javascript-runtime
How to implement setInterval?
- Dominant language
- Rust
- Stars
- 350
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
Hello.
I had so much fun following this tutorial.
I implemented setTimeout using the answer to my question here https://github.com/denoland/deno/discussions/19231
```rust
#[op]
async fn op_set_timeout(delay: u64) -> Result<(), AnyError> {
tokio::time::sleep(tokio::time::Duration::from_millis(delay)).await;
Ok(())
}
```
This works fine because it does nothing but wait and then return to JavaScript where we can execute the callback.
But how could we implement setInterval?
We need to execute the JavaScript callback after every delay, and also return a timer ID so that JavaScript could cancel it later. I don't get how to do all of that in a single function.
So, could you please help me? Thanks in advance!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.