Best way to start multiple workers

Hello all,

First of all apologies if this is bit off topic..

I already have a working HTTPS server that's listening in a loop{} and tokio handles the spawning part of the HTTP part.

I'd like to create new "workers" (sorry if not the right term) that would do be independent of the main loop and do their own thing. Like a timed task that would do things ever x minutes/seconds. Or potentially create a another TcpListener on another port that would be like a "management interface".
Well, the use case is something I'll figure out later, but the main point is..

How'd I'd get about this. I tried searching, thought I'd ask here as there were number of questions and answers that helped me immensely.

Thank you!

Just put that stuff in a tokio::task::spawn / tokio::task::spawn_blocking of its own. It will run it in parallel to your other tasks on the worker threads or in case you need to spawn something synchronous on a dedicated thread so it won't bother the runtime. Here a link to the (probably) most referenced resource here on URLO: Async: What is blocking? – Alice Ryhl. It's a great read on what kind of tasks should be spawned how.


Thank you, this clears so much things, and a great post by Alice.

1 Like