More concurrent + parallel question

Follow up on How to run infinite concurrent and parallel tasks? - #8 by Geobomatic
If I understand properly now, when using tokio:

let rt = Runtime::new()?;
rt.block_on(server::start_warp_server())

And in warp endpoint having this kind of code:

let get_endpoint = warp::path("endpoint").and(warp::query()).and_then(
        move |params: HashMap<String, String>| {
            async move {
                crate::process_request(params)
                    .await
                    .map_err(warp::reject::custom::<error::ServerError>)
            }
        },
    );

process_request will never be executed in a new thread?

If I want to use the multi-threading capability of tokio's rt-multi-thread runtime, I need to spawn on each endpoint? Like this:

let get_endpoint = warp::path("endpoint").and(warp::query()).and_then(
        move |params: HashMap<String, String>| {
            async move {
                tokio::spawn(crate::process_request(params))
                    .await
                    .map_err(warp::reject::custom::<error::ServerError>)
            }
        },
    );

Am I right?

I'm pretty sure that warp has the appropriate calls to tokio::spawn internally.

1 Like

Thank you, some ripgrep later, it seems it's done in hyper (not 100% sure, but from a quick look, it seems so :smiley: )

Ah, yes, that sounds about right.