I'm fairly new the the async world and I think I just don't know the right pattern for what I'm trying to achieve.
I'd like to have a periodic background timer which fires an HTTP-request. I'm not interested in the result and I don't care if this blocks or if the timings are precise. The method for firing the request is async.
First, using tokio::spawn instead of thread::spawn is the probably the best option here.
If you really want to run it on an actual dedicated thread, I would recommend obtaining a Handle to an existing runtime and using the block_on method from that runtime. If you don't have an existing runtime, I would recommend creating a current_thread runtime instead. For more details on this topic, see Bridging with sync code from the Tokio website.
Note that you shouldn't be using tokio::spawn if you really want a dedicated thread. Using tokio::spawn will run it on one of the runtime's own worker threads instead.
It's actually ok in this case because the use of the block_on call makes it happen outside the runtime's async context.
Thank you both for your help!
Using tokio::spawn with an async looks ideomatic and I think I begin to understand how the async infrastructure works. Moving to an async closure made me switch to time::interval which now feels natural as well.
I finally have to deep dive into tokio as it's becoming ubiquitous - no more excuses