Commit Graph
11 Commits
Author SHA1 Message Date
Qi b8318fa172 task: add tests for spawn_local in panic scenarios (#7694)
Signed-off-by: ADD-SP <[email protected]>
2025-10-20 20:25:00 +08:00
FrancescoV1985 5dacc2e2a8 task: add tests for spawn_local and spawn_local_on (#7609)
Add tests for task collections (TaskTracker, JoinSet, JoinMap).
2025-10-16 23:44:57 +08:00
Conrad Ludgate 416e36b0df task: stabilise JoinMap (#7075) 2025-08-03 07:58:28 +00:00
Conrad Ludgate 9e94fa7e15 task: remove raw-entry feature from hashbrown dep (#7252) 2025-07-22 15:52:54 +02:00
shangchenglumetro a1ee3ef218 chore: fix some minor typos in the comments (#7442)
Signed-off-by: shangchenglumetro <[email protected]>
2025-07-04 11:29:27 +02:00
Conrad Ludgate c3037adac9 task: properly handle removed entries in JoinMap (#7264) 2025-04-15 16:33:20 +02:00
Taiki Endo 7f09959b0a chore: use [lints] to address unexpected_cfgs lint (#7124) 2025-01-25 17:46:21 +01:00
Alice Ryhl 2a0df5fb05 ci: bump nightly to nightly-2024-05-05 (#6538) 2024-05-05 15:43:11 +00:00
Andrea StedileandAlice Ryhl f1e41a4ad4 task: add JoinMap::keys (#6046)
Co-authored-by: Alice Ryhl <[email protected]>
2023-10-15 16:47:41 +02:00
David Barsky 08d49532b4 joinset: rename join_one to join_next (#4755) 2022-06-09 22:41:25 +02:00
Eliza Weisman d456706528 util: implement JoinMap (#4640)
## Motivation

In many cases, it is desirable to spawn a set of tasks associated with
keys, with the ability to cancel them by key. As an example use case for
this sort of thing, see Tower's [`ReadyCache` type][1].

Now that PR #4530 adds a way of cancelling tasks in a
`tokio::task::JoinSet`, we can implement a map-like API based on the
same `IdleNotifiedSet` primitive.

## Solution

This PR adds an implementation of a `JoinMap` type to
`tokio_util::task`, using the `JoinSet` type from `tokio::task`, the
`AbortHandle` type added in #4530, and the new task IDs added in #4630.

Individual tasks can be aborted by key using the `JoinMap::abort`
method, and a set of tasks whose key match a given predicate can be
aborted using `JoinMap::abort_matching`.

When tasks complete, `JoinMap::join_one` returns their associated key
alongside the output from the spawned future, or the key and the
`JoinError` if the task did not complete successfully.

Overall, I think the way this works is pretty straightforward; much of
this PR is just API boilerplate to implement the union of applicable
APIs from `JoinSet` and `HashMap`. Unlike previous iterations on the
`JoinMap` API (e.g. #4538), this version is implemented entirely in
`tokio_util`, using only public APIs from the `tokio` crate. Currently,
the required `tokio` APIs are unstable, but implementing `JoinMap` in
`tokio-util` means we will never have to make stability commitments for
the `JoinMap` API itself.

[1]: https://github.com/tower-rs/tower/blob/master/tower/src/ready_cache/cache.rs

Signed-off-by: Eliza Weisman <[email protected]>
2022-04-26 17:25:48 +00:00