Commit Graph
19 Commits
Author SHA1 Message Date
Rafael Bachmann 1ac8dff213 task: add AbortOnDropHandle type (#6786) 2024-08-20 10:58:04 +02:00
dpl 70569bd009 task: fix typo in TaskTracker docs (#6792) 2024-08-18 15:09:19 +02:00
LongYinan 9ed595767d wasm: support rt-multi-thread with wasm32-wasi-preview1-threads (#6510) 2024-04-24 09:45:54 +02:00
Rafael Bachmann be9328da75 chore: fix clippy warnings (#6466) 2024-04-08 20:44:18 +09:00
Owen Leung 131e7b4e49 ci: add spellchecking (#6297) 2024-01-29 10:53:43 +01:00
Alice Ryhl c7e7f203ee chore: typographic improvements (#6262) 2024-01-03 18:01:27 +00:00
Alice Ryhl 70410836ae task: add tokio_util::sync::TaskTracker (#6033) 2023-10-22 14:35:19 +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
tim gretler b8af5aad16 task: add spawn_blocking methods to JoinMap (#5797) 2023-06-24 12:13:56 +02:00
Abutalib Aghayev 71bd49e146 task: add task::id() and task::try_id() (#5171) 2022-11-13 14:18:42 +01:00
Noah Kennedy b67b8c1398 chore: stabilize JoinSet and AbortHandle (#4920)
Closes #4535.

This leaves the ID-related APIs unstable.
2022-08-19 17:16:11 +00:00
Richard Zak 6d3f92dddc wasm: initial support for wasm32-wasi target (#4716)
This adds initial, unstable, support for the wasm32-wasi target. Not all of Tokio's
features are supported yet as WASI's non-blocking APIs are still limited.

Refs: tokio-rs/tokio#4827
2022-07-12 13:20:26 -07:00
Hayden Stainsby ad412a9833 util: add track_caller to public APIs (#4785)
* util: add track_caller to public APIs

Functions that may panic can be annotated with `#[track_caller]` so that
in the event of a panic, the function where the user called the
panicking function is shown instead of the file and line within Tokio
source.

This change adds `#[track_caller]` to all the non-unstable public APIs in
tokio-util where the documentation describes how the function may panic
due to incorrect context or inputs.

In one place, an assert was added where the described behavior appeared
not to be implemented. The documentation for `DelayQueue::reserve`
states that the function will panic if the new capacity exceeds the
maximum number of entries the queue can contain. However, the function
didn't panic until a higher number caused by an allocation failure. This
is inconsistent with `DelayQueue::insert_at` which will panic if the
number of entries were to go over MAX_ENTRIES.

Tests are included to cover each potentially panicking function.

Refs: #4413

* fix tests on FreeBSD 32-bit (I hope)

Some tests were failing on FreeBSD 32-bit because the "times too far in
the future" for DelayQueue were also too far in the future for the OS.

Fixed by copying the MAX_DURATION value from where it's defined and
using it to create a duration that is just 1 more than the maximum. This
will start to break once we get close (within 2 and a bit years) of the
Epochalypse (19 Jan, 2038) - but a lot of other things are going to be
breaking on FreeBSD 32-bit by then anyway.
2022-06-27 12:31:31 +02:00
b-naber d8fb721de2 task: improve LocalPoolHandle (#4680) 2022-06-17 18:37:00 +02:00
David Barsky 08d49532b4 joinset: rename join_one to join_next (#4755) 2022-06-09 22:41:25 +02:00
Alice Ryhl 5fd1220c73 task: update return value of JoinSet::join_one (#4726) 2022-05-31 09:15:37 +02:00
Eliza Weisman 052355f064 task: add #[track_caller] to JoinSet/JoinMap (#4697)
## Motivation

Currently, the various spawning methods on `tokio::task::JoinSet` and
`tokio_util::task::JoinMap` lack `#[track_caller]` attributes, so the
`tracing` spans generated for tasks spawned on `JoinSet`s/`JoinMap`s
will have the `JoinSet` spawning method as their spawn location, rather
than the user code that called that method.

## Solution

This PR fixes that by...adding a bunch of `#[track_caller]` attributes.

## Future Work

In the future, we may also want to consider adding additional data to
the task span indicating that the task is spawned on a `JoinSet`...

Signed-off-by: Eliza Weisman <[email protected]>
2022-05-16 16:36:24 +00: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
Mark Drobnak 257053e40b util: add spawn_pinned (#3370) 2022-01-27 15:26:09 +01:00