How to run a function in a nonblocking way that accepts !Send value

⚓ rust    📅 2025-05-23    👤 surdeus    👁️ 4      

surdeus

Warning

This post was published 37 days ago. The information described in this article may have changed.

Hi,

I need to run a function that takes non send value but the function has to run in a non blocking way. Result of the function is not important(if there is a way to gather it's result it's a plus).

#[tokio::main]
async fn main() {
    let non_send_value = tokio::spawn(task_that_returns_non_send_value()).await;

    // this has to be nonblocking and result is not that important
    function_that_uses_non_send_value(non_send_value); 
}

You may ask why you use tokio main macro or why did you spawn first task with tokio spawn because I'm using a workflow that is similar to this and I can not modify it probably. This is a minimum example. I have limited permission to change things.

1 post - 1 participant

Read full topic

🏷️ rust_feed