Is it okay to use tokio::spawn in an actix_rt context?

Hi, I am just getting my hands wet with the async stuff for the past month or two but still many things are pretty confusing and too much magical :slight_smile:
I have a actix webserver and I need to spawn some async tasks before in couple places I used actix_rt::spawn for these sort of things but the module I am working on contains helpers and I really dont want it to include actix_rt as dependency
In actix context is it alright to use tokio::spawn as far as I know what actix_rt does is to start a tokio runtime so in theory it should be fine but I couldnt be sure.

1 Like

I believe that should be fine. If an actix system isn’t started when calling spawn, then it will panic.

The actix-web::System uses a tokio runtime under the hood so in my experience there is no problem mixing tokio related crates with actix-web. For example I use tokio::task::spawn_blocking to do synchronous IO during web-requests and everything works fine.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.