Will reqwest::blocking block my main-thread in this case?


I have an Actix-web project.

async fn main() -> std::io::Result<()> {

    // Cronjob
    let mut cron = CronJob::new("Test", cronjob_function);
    cron.seconds("20"); // Executed every minute in this example
    CronJob::start_job_threaded(cron); // Threaded

    // start http server
    HttpServer::new(move || {
        // Code and services for Actix-web

I have a test-function which gets executed when the route /test gets a POST-request:

pub async fn test(bytes: Bytes, req: HttpRequest) -> Result<HttpResponse> {

This is my cronjob-function:

pub fn cronjob_function(name: &str) {
    let client = reqwest::blocking::Client::new();
    let res = client

Basically cronjob_function gets executed every minute. It sends POST-request to /test resulting in the function test() being executed.

Note that in cronjob_function I am using reqwest::blocking which is a synchronous version of reqwest meaning that the thread it runs on stops until the POST-request is finished.

The question I have is if with this approach I will block my Actix webserver? Normally cronjob_function should be executed on a separate thread because I am using CronJob::start_job_threaded(cron);. Does that mean that only the thread for the cronjob gets 'blocked' by the request and not my main-thread where Actix runs on?




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.