Hi all, I'm looking to use scoped async such that I can take a mutable borrow into a spawn. I'm currently using async-scoped and that works, but I also want to give the spawned tasks names. I see that I can use tokio::task::Builder for this, but the type signature for Builder.spawn is incompatible for async-scoped.
Using Builder.spawn directly doesn't work because of lifetime issues with shards, and I can't wrap shards in an Arc<RwLock<Vec<...>>> because of lifetime issues with Builder.spawn.
I've also looked at using FuturesUnordered, but that doesn't appear to support creating named tasks either.
For reference, I want to give my tasks names so they show up in tokio-console for debugging purposes.
My code looks something like this:
async fn main() -> anyhow::Result<()> {
...
run_events(&mut shards);
shard_resume::dump_resumes(&shards, cluster).await?;
}
fn run_events(
shards: &mut Vec<Shard<Queue>>,
cluster: Arc<Cluster>,
) {
let shutdown_token = CancellationToken::new();
async_scoped::TokioScope::scope_and_block(|scope| {
for shard in shards {
scope.spawn(shard_runner(shard, shutdown_token));
}
scope.spawn(kill_shards_on_exit(cluster, shutdown_token));
});
}