I have 3 different async methods say func1, func2, func3 on a struct object.
What I want to accomplish is something like:
loop {
obj.func1().await;
set_timeout(Duration::from_secs(5)).await;
}
loop {
obj.func2().await;
set_timeout(Duration::from_secs(5)).await;
}
loop {
obj.func3().await;
set_timeout(Duration::from_secs(5)).await;
}
I want all these 3 loops to run in parallel. Obviously, in this form it won't work because the 2nd and 3rd loops will be unreachable.
I've thought of the below solution:
loop {
thread::spawn(move || async move {
obj.func1().await;
obj.func2().await;
obj.func3().await;
set_timeout(Duration::from_secs(5)).await;
});
}
But it has 2 issues:
- My struct does not implement the
Copytrait (using some 3rd party crates, so cannot do much there). - As every function call will run as a seperate thread here, I doubt the timeout will work properly here!
How should I approach this?