Hello! There's a function I need to run an async function every so often while keeping the Rocket webapp running. Basically I want rocket to continue serving normally while I have another async function doing its thing. I haven't found a go-to way to do this and spawning an additional tokio runtime that would let me run both the whole rocket and my other function side-by-side seems overkill. What do you think/recommend?
#Running async function periodically with Rocket
8 messages · Page 1 of 1 (latest)
tokio::spawn with a loop in it before starting the server
Thanks! I should really read up about tokio to have a better overview of how it works and common patterns. Is there some kind of introductory guide?
Tokio is a runtime for writing reliable asynchronous applications with Rust. It provides async I/O, networking, scheduling, timers, and more.
Perfect, thanks!
Also, you wanted to make it only run periodically, I believe you could await on a sleep call in the task...?
Creates new [Interval] that yields with interval of period. The first tick completes immediately. The default [MissedTickBehavior] is Burst, but this can be configured by calling set_missed_tick_behavior.
I'm doing something like that yes, thanks
