When I read the tokio docs I see nice greenfields projects where
main() creates a future and does
tokio::run(). Everything’s async, you can call
tokio::spawn whenever you like, and stuff magically attaches to the executor.
Does anyone have any examples or articles that would help with adding tokio to a project that doesn’t have an executor? As a concrete example, I have a function that fires a callback when it’s finished. This could easily be returning an
impl Future instead. I already have async code in place that runs when it completes, that I could use to trigger
notify() on the task instead of run the callback. But I have no idea where to put the tokio Runtime. The caller of the function isn’t a tokio function so it can’t
spawn() the task.
I suppose the key thing is that there doesn’t seem to be an equivalent of iOS
dispatch_async that I can use to push async tasks into the tokio thread pool when I’m operating outside that context. How can I move into tokio when I’m not already inside it?