As the subject says, I don't fully understand why something like this work
async task1(arg: &String) {...}
async task2(arg: &String) {...}
#[tokio::main]
async fn main()
{
let data = "hello".to_owned();
tokio::join!(task1(&data), task2(&data));
...
}
But this doesn't
#[tokio::main]
async fn main()
{
let data = "hello".to_owned();
tokio::join!(tokio::spawn(task1(&data)), tokio::spawn(task2(&data)));
...
}
I kind of understand why tokio::spawn requires for the passed-in futures to be 'static, but I can't fit in my (possibly poor) mental model why that's not the case when passing the futures directly to tokio::join! as in the first example.
Maybe it's related to the fact that without spawn
the two futures are driven to completion on the same thread the calling function is executing?
But even if that's the case I'd like for someone to elaborate a bit on the reasoning to use here...
Thanks