#Running async function periodically with Rocket

8 messages · Page 1 of 1 (latest)

languid kindle
#

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?

blazing pecan
#

tokio::spawn with a loop in it before starting the server

languid kindle
#

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?

blazing pecan
languid kindle
#

Perfect, thanks!

raven niche
#

Also, you wanted to make it only run periodically, I believe you could await on a sleep call in the task...?

languid kindle