This commit adds `set_default` drop guard style APIs for setting the
default reactor, executor, and timer. These are similar to the APIs used
in `tokio` 0.2
In addition to having potentially better ergonomics than the
`with_default` closure APIs, the drop-guard based APIs will be helpful
in rewriting the `tokio-compat` crate to wrap the existing tokio 0.2
runtime, rather than constructing its own runtime.
Because the runtime does not expose an `around_worker` API, it cannot
currently be used with the 0.1 `with_default` method of setting the
reactor, timer, and executor. This means that tokio-compat must
duplicate a lot of existing code from `tokio` to construct the runtime,
which is unfortunate (and has the potential to introduce errors). On the
other hand, we can use the drop guard APIs with `before_start` and
`after_stop`, by storing the drop guards in a thread-local. This will
allow `tokio-compat` to wrap the 0.2 runtime, reducing code duplication.
Also, this will allow the blocking pool to be used on the compat
runtime, which is currently impossible (as the blocking APIs are private
to `tokio`).
Signed-off-by: Eliza Weisman <[email protected]>
* use dyn Trait syntax where appropriate
recent rust nightly started warning that not using `dyn` was
deprecated. This requires MSRV 1.27.0+.
* rustfmt fallout from dyn additions
* stop explicit allow of rust_2018_idioms
* more dyn Trait syntax
* drop tokio-macros from 0.1.x workspace
Since tokio-macros specifies an edition=2018, we would otherwise
require MSRV 1.31.0 to build/test it. And tokio-macros isn't used with
tokio 0.1.x.
* reactor: narrow tokio-io-pool dev dep to 0.1.4
Since 0.1.5-6 is now a edition=2018 crate, which has effective MSRV
1.31.0.
* narrow tempfile dev-dep to avoid MSRV bump
tempfile 3.1.0 pulls in rand 0.7.0 and is MSRV 1.32.0
* narrow flate2 dev-dep to avoid MSRV bump
flate2 1.0.10-11 have MSRV 1.34.0.
github refs: alexcrichton/flate2-rs#207
* fs: drop deprecated tempdir crate use in tests
In particular because it pulls in old rand duplicates. Replace use
with tempfile::tempdir() which has been available since tempfile
3.0.0.
backport-of: #1312
* increase CI MSRV to 1.28.0
* docs: fixed links to tokio_timer::clock::Now in tokio-timer/src/timer/mod.rs
* docs: fixed links to std::time::Instant in tokio-timer/src/timer/mod.rs
This reverts commit 7a49ebb65e.
The commit conflicted with another change that was merged, causing CI to fail. The public API
also requires a bit more refinement (#833) and Tokio crates need to be released.
Error::cause is deprecated in Rust 1.33, but this allows Error::cause
until the minimum supported version of tokio is Rust 1.30.
When the minimum support version of tokio reaches Rust 1.30,
replace Error::cause with Error::source.
Fixes: #817
This also bumps a number of sub crates:
* tokio-executor (0.1.3)
* tokio-io (0.1.8)
* tokio-reactor (0.1.4)
* tokio-threadpool (0.1.6)
* tokio-timer (0.2.6)
* tokio-udp (0.1.2)
This patch introduces `Timeout`. This new type allows setting a timeout
both using a duration and an instant. Given this overlap with
`Deadline`, `Deadline` is deprecated.
In addition to supporting future timeouts, the `Timeout` combinator is
able to provide timeout functionality to streams. It does this by
applying a duration based timeout to each item being yielded.
The main reason for introducing `Timeout` is that a deadline approach
does not work with streams. Since `Timeout` needed to be introduced
anyway, keeping `Deadline` around does not make sense.
* Remove `counted` field on `timer::Entry`.
It turns out that a better indicator of whether or not the number of
active timeouts should be decremented is if the `Entry` has been
associated with a timer. In other words, if `Entry::inner` can be
upgraded, then the count should be decremented on drop.
* timer: Tweak link between `Delay` and the driver
This tweaks the struct layout / details regarding how a `Delay` instance
is linked to a driver (timer instance). Instead of lazily allocating the
`Entry` (node shared between `Delay` and the timer), `Entry` is
allocated immediately when `Delay` is created. This allows using the
entry store data used by `Delay`.
This is in anticipation of further timer improvements that would
otherwise require the size of `Delay` to grow further. Since an
allocation is already made, the idea is to shrink the size of the
`Delay` struct.
This patch adds a `DelayQueue` to tokio_timer. The `DelayQueue` allows
inserting elements as well as specifying a time at which the element
should be returned to the user. This allows handling more complex
timeout situations.
This patch implements `Default` for `tokio_timer::Handle`. It returns a
`Handle` instance that is not bound to a specific timer. Instead, it
will use the timer for the current execution context. This is the same
strategy used by `tokio_reactor::Handle`.
Fixes#547
* Normalize links to docs.rs/CRATE/M.N/...
docs.rs is smart enough to show docs for the latest M.N.P release when
M.N is used in the link. For example:
https://docs.rs/mio/0.6/mio/struct.Poll.html
..will show mio 0.6.14 and later docs. While using the `M.N.*`
(ASTERISK) syntax also works, `M.N` is the more common usage, so
standarize a few existing links to that format.
* Fix missing or malformed rustdoc links
* executor lib rustdoc minor format change
* Promote tokio-threadpool crate level comments to rustdoc
* Replace hidden tokio::executor::thread_pool docs with deprecation note
* Fix typo/simplify util module rustdoc
* Reuse some tokio::executor::thread_pool rustdoc for the crate
Relates to #421
Currently, the timer uses a `Now` trait to abstract the source of time.
This allows time to be mocked out. However, the current implementation
has a number of limitations as represented by #288 and #296.
The main issues are that `Now` requires `&mut self` which prevents a
value from being easily used in a concurrent environment. Also, when
wanting to write code that is abstract over the source of time, generics
get out of hand.
This patch provides an alternate solution. A new type, `Clock` is
provided which defaults to `Instant::now` as the source of time, but
allows configuring the actual source using a new iteration of the `Now`
trait. This time, `Now` is `Send + Sync + 'static`. Internally, `Clock`
stores the now value in an `Arc<Now>` value, which introduces dynamism
and allows `Clock` values to be cloned and be `Sync`.
Also, the current clock can be set for the current execution context
using the `with_default` pattern.
Because using the `Instant::now` will be the most common case by far, it
is special cased in order to avoid the need to allocate an `Arc` and use
dynamic dispatch.
This patch renames `Sleep` from tokio-timer and the tokio facade to
`Delay`. Given that the future does not actually put anything to sleep,
the `Delay` name feels more appropriate.
Fixes#263
This patch adds a new crate: tokio-timer. This crate provides an
efficient timer implemeentation designed for use in Tokio based
applications.
The timer users a hierarchical hashed timer wheel algorithm with six
levels, each having 64 slots. This allows the timer to have a resolution
of 1ms while maintaining O(1) complexity for insert, removal, and firing
of timeouts.
There already exists a tokio-timer crate. This is a complete rewrite
which solves the outstanding problems with the existing tokio-timer
library.
Closes#146.