69 Commits

Author SHA1 Message Date
Daniel Bloom
c999699f5e
sync: remove 'static bound from PollSender (#5665) 2023-05-09 16:01:57 +00:00
isabelleatkins
9f9e596eec
time: fix panic in DelayQueue (#5630) 2023-04-17 20:51:42 +00:00
Jens Reidel
effead29d1
time: add DelayQueue::peek (#5569)
Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2023-04-16 09:43:03 +02:00
Alice Ryhl
2dfe4e8885
time: fix repeatedly_reset_entry_inserted_as_expired test (#5570) 2023-03-21 18:06:22 +01:00
Carl Lerche
22cff80048
chore: update CI's clippy version to 1.65 (#5276) 2022-12-06 19:56:13 -08:00
Jiahao XU
304b5152a7
sync: add owned future for CancellationToken (#5153) 2022-11-21 15:03:09 +00:00
Alice Ryhl
fc9518b627
chore: bump clippy version (#5173) 2022-11-06 12:44:26 +01:00
Daniel Bischof
620880f4ca
io: add tokio_util::io::{CopyToBytes, SinkWriter} (#5070)
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
Co-authored-by: Simon Farnsworth <simon@farnz.org.uk>
2022-10-30 11:04:22 +00:00
Duarte Nunes
29c6de0e3e
sync: add PollSemaphore::poll_acquire_many (#5137) 2022-10-30 10:06:10 +01:00
crusader-mike
cbbf81b922
codec: expose backpressure_boundary in Framed API (#5124) 2022-10-29 14:59:22 +00:00
Simon Farnsworth
96fab053ab
io: wrappers for inspecting data on IO resources (#5033) 2022-09-28 18:21:51 +00:00
imlk
733931d85f
io: add SyncIoBridge::shutdown() (#4938) 2022-08-24 12:18:53 +00:00
Josh Soref
f3e340a35b
chore: fix spelling mistakes (#4858)
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-07-25 07:26:01 +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
Sabrina Jewson
f7346f04af
util: simplify ReusableBoxFuture (#4675) 2022-05-13 23:39:13 +02:00
Finomnis
addf5b5749
sync: rewrite CancellationToken (#4652) 2022-05-13 23:26:15 +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 <eliza@buoyant.io>
2022-04-26 17:25:48 +00:00
Toby Lawrence
52fb93dce9
sync: refactored PollSender<T> to fix a subtly broken Sink<T> implementation (#4214)
Signed-off-by: Toby Lawrence <toby@nuclearfurnace.com>
2022-02-09 12:09:04 -05:00
Benjamin Saunders
cf38ba627a
util: remove error case from the infallible DelayQueue::poll_elapsed (#4241) 2022-02-08 21:07:33 -05:00
Sunyeop Lee
0b05ef638d
codec: implement Encoder<BytesMut> for BytesCodec (#4465) 2022-02-08 09:11:24 -05:00
Mark Drobnak
257053e40b
util: add spawn_pinned (#3370) 2022-01-27 15:26:09 +01:00
Luiz Carlos
2a5071fc2d
feat: implement Framed::map_codec (#4427) 2022-01-27 12:37:30 +01:00
b-naber
c800deaacc
util: add shrink_to_fit and compact methods to DelayQueue (#4170) 2022-01-09 12:41:30 +01:00
Bhargav
0c68b89452
codec: update stream impl for Framed to return None after Err (#4166) 2021-10-26 16:56:15 +02:00
Alice Ryhl
e04b5be1f5
time: update deadline on removal in DelayQueue (#4178) 2021-10-22 20:34:36 +02:00
Colin Walters
2734fa9a85
util/io: add SyncIoBridge (#4146) 2021-10-22 18:46:29 +02:00
LinkTed
8198ef3881
chore: fix clippy warnings (#4017) 2021-08-03 10:50:40 +02:00
Taiki Endo
9d8b37d51a
macros: suppress clippy::default_numeric_fallback lint in generated code (#3831) 2021-06-02 18:16:23 +09:00
Kai Mast
55c5d12451
util: require full feature in tokio-util tests (#3636) 2021-05-05 18:21:25 +09:00
Evan Cameron
9eeec039f2
util: make UdpFramed take Borrow<UdpSocket> (#3451) 2021-04-14 20:16:23 +02:00
somethingelseentirely
8ed825fd49
util: makes Framed and FramedStream resumable after eof (#3272) 2021-03-22 09:09:01 +01:00
Alice Ryhl
db1d90453c
util: fuse PollSemaphore (#3578) 2021-03-09 19:22:36 +01:00
Alice Ryhl
0867a6fc03
util: add pollable mpsc::Sender (#3490) 2021-03-04 17:29:30 +01:00
r-zig
5756a005a6
codec: LinesCodec should only return MaxLineLengthExceeded once per line (#3556) 2021-02-25 23:21:59 +01:00
r-zig
c9d2a36c7b
codec: AnyDelimiter codec (#3406) 2021-02-23 16:56:11 +01:00
Alice Ryhl
891aba5f71
util: add ReusableBoxFuture utility (#3464) 2021-01-30 00:03:01 +01:00
William Bain
c4f66ed121
util: fix panics on updating DelayQueue entries (#3270) 2021-01-21 10:56:44 +01:00
Alice Ryhl
78f2340d25
tokio: remove prelude (#3299)
Closes: #3257
2020-12-19 11:42:24 -08:00
Lucio Franco
8efa62013b
Move stream items into tokio-stream (#3277)
This change removes all references to `Stream` from
within the `tokio` crate and moves them into a new
`tokio-stream` crate. Most types have had their
`impl Stream` removed as well in-favor of their
inherent methods.

Closes #2870
2020-12-15 20:24:38 -08:00
bdonlan
ae67851f11
time: use intrusive lists for timer tracking (#3080)
More-or-less a half-rewrite of the current time driver, supporting the
use of intrusive futures for timer registration.

Fixes: #3028, #3069
2020-11-23 10:42:50 -08:00
Evan Cameron
47658a6da5
util: resurrect UdpFramed (#3044) 2020-11-06 16:59:15 +01:00
Taiki Endo
c90681bd8e
rt: simplify rt-* features (#2949)
tokio:

    merge rt-core and rt-util as rt
    rename rt-threaded to rt-multi-thread

tokio-util:

    rename rt-core to rt

Closes #2942
2020-10-12 14:13:23 -07:00
Lucio Franco
8880222036
rt: Remove threaded_scheduler() and basic_scheduler() (#2876)
Co-authored-by: Alice Ryhl <alice@ryhl.io>
Co-authored-by: Carl Lerche <me@carllerche.com>
2020-10-12 13:44:54 -04:00
Lucio Franco
f8c91f2ead
io: Rename ReadBuf methods (#2945)
This changes `ReadBuf::add_filled` to `ReadBuf::advance` and
`ReadBuf::append` to `ReadBuf::put_slice`. This is just a
mechanical change.

Closes #2769
2020-10-12 12:41:40 -04:00
bdonlan
b704c53b9c
chore: Fix clippy lints (#2931)
Closes: #2929

Co-authored-by: Bryan Donlan <bdonlan@amazon.com>
2020-10-08 17:14:39 -07:00
bdonlan
9730317e94
time: move DelayQueue to tokio-util (#2897)
This change is intended to do the minimum to unblock 0.3; as such, for now, we
duplicate the internal `time::wheel` structures in tokio-util, rather than trying
to refactor things at this stage.

Co-authored-by: Bryan Donlan <bdonlan@amazon.com>
2020-10-05 14:25:04 -07:00
Juan Alvarez
53ccfc1fd6
time: introduce sleep and sleep_until functions (#2826) 2020-10-01 09:24:33 +02:00