I have a tokio::JoinSet with n tasks. Tasks look like something like this:
async fn task(some_data : MyStruct, shared : Arc<Mutex<HashMap<String,String>>>) -> bool {
if some_data.condition() {
loop {
if !shared.lock().unwrap().contains_key(some_data.x) {
_ = tokio::time::sleep(Duration::from_secs(1)).await;
}
else {
break;
}
}
}
// rest of the code
}```
I then spawn the tasks and process them like this:
```rs
while let Some(success) = set.join_next().await {
match success {
Ok(success) => {
if !success {
set.shutdown().await;
print_something();
return false;
}
}
// ...
}
}
All the tasks that don't satisfy the condition() and thus don't enter the loop, get aborted. All the tasks that enter the loop are never aborted, and are stuck in an infinite loop of checking and sleeping. The shutdown().await never ends and the program doesn't exit. How do I abort them? I've tried tokio::select but didnt have much luck either there.