Skip to content

Commit

Permalink
Merge branch 'tokio-rs:master' into localset_enter_4736
Browse files Browse the repository at this point in the history
  • Loading branch information
gftea committed Jun 16, 2022
2 parents a0431cd + 90bc5fa commit a2007ac
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -5,7 +5,7 @@ jobs:
image: ubuntu-2004:202101-01
resource_class: arm.medium
environment:
# Change to pin rust versino
# Change to pin rust version
RUST_STABLE: stable
steps:
- checkout
Expand Down
118 changes: 113 additions & 5 deletions tokio-macros/src/lib.rs
Expand Up @@ -265,11 +265,20 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
entry::main(args, item, false)
}

/// Marks async function to be executed by runtime, suitable to test environment
/// Marks async function to be executed by runtime, suitable to test environment.
/// This macro helps set up a `Runtime` without requiring the user to use
/// [Runtime](../tokio/runtime/struct.Runtime.html) or
/// [Builder](../tokio/runtime/struct.Builder.html) directly.
///
/// ## Usage
/// Note: This macro is designed to be simplistic and targets applications that
/// do not require a complex setup. If the provided functionality is not
/// sufficient, you may be interested in using
/// [Builder](../tokio/runtime/struct.Builder.html), which provides a more
/// powerful interface.
///
/// ### Multi-thread runtime
/// # Multi-threaded runtime
///
/// To use the multi-threaded runtime, the macro can be configured using
///
/// ```no_run
/// #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
Expand All @@ -278,9 +287,52 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
/// }
/// ```
///
/// ### Using default
/// The `worker_threads` option configures the number of worker threads, and
/// defaults to the number of cpus on the system. This is the default
/// flavor.
///
/// Note: The multi-threaded runtime requires the `rt-multi-thread` feature
/// flag.
///
/// # Current thread runtime
///
/// The default test runtime is single-threaded. Each test gets a
/// separate current-thread runtime.
///
/// ```no_run
/// #[tokio::test]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
///
/// ## Usage
///
/// ### Using the multi-thread runtime
///
/// ```no_run
/// #[tokio::test(flavor = "multi_thread")]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
///
/// Equivalent code not using `#[tokio::test]`
///
/// ```no_run
/// #[test]
/// fn my_test() {
/// tokio::runtime::Builder::new_multi_thread()
/// .enable_all()
/// .build()
/// .unwrap()
/// .block_on(async {
/// assert!(true);
/// })
/// }
/// ```
///
/// The default test runtime is single-threaded.
/// ### Using current thread runtime
///
/// ```no_run
/// #[tokio::test]
Expand All @@ -289,6 +341,46 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
/// }
/// ```
///
/// Equivalent code not using `#[tokio::test]`
///
/// ```no_run
/// #[test]
/// fn my_test() {
/// tokio::runtime::Builder::new_current_thread()
/// .enable_all()
/// .build()
/// .unwrap()
/// .block_on(async {
/// assert!(true);
/// })
/// }
/// ```
///
/// ### Set number of worker threads
///
/// ```no_run
/// #[tokio::test(flavor ="multi_thread", worker_threads = 2)]
/// async fn my_test() {
/// assert!(true);
/// }
/// ```
///
/// Equivalent code not using `#[tokio::test]`
///
/// ```no_run
/// #[test]
/// fn my_test() {
/// tokio::runtime::Builder::new_multi_thread()
/// .worker_threads(2)
/// .enable_all()
/// .build()
/// .unwrap()
/// .block_on(async {
/// assert!(true);
/// })
/// }
/// ```
///
/// ### Configure the runtime to start with time paused
///
/// ```no_run
Expand All @@ -298,6 +390,22 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
/// }
/// ```
///
/// Equivalent code not using `#[tokio::test]`
///
/// ```no_run
/// #[test]
/// fn my_test() {
/// tokio::runtime::Builder::new_current_thread()
/// .enable_all()
/// .start_paused(true)
/// .build()
/// .unwrap()
/// .block_on(async {
/// assert!(true);
/// })
/// }
/// ```
///
/// Note that `start_paused` requires the `test-util` feature to be enabled.
///
/// ### Rename package
Expand Down
4 changes: 2 additions & 2 deletions tokio-stream/src/stream_ext.rs
Expand Up @@ -1070,10 +1070,10 @@ impl<St: ?Sized> StreamExt for St where St: Stream {}
/// Merge the size hints from two streams.
fn merge_size_hints(
(left_low, left_high): (usize, Option<usize>),
(right_low, right_hign): (usize, Option<usize>),
(right_low, right_high): (usize, Option<usize>),
) -> (usize, Option<usize>) {
let low = left_low.saturating_add(right_low);
let high = match (left_high, right_hign) {
let high = match (left_high, right_high) {
(Some(h1), Some(h2)) => h1.checked_add(h2),
_ => None,
};
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/codec/decoder.rs
Expand Up @@ -20,7 +20,7 @@ use std::io;
/// it's possible to temporarily read 0 bytes by reaching EOF.
///
/// In these cases `decode_eof` will be called until it signals
/// fullfillment of all closing frames by returning `Ok(None)`.
/// fulfillment of all closing frames by returning `Ok(None)`.
/// After that, repeated attempts to read from the [`Framed`] or [`FramedRead`]
/// will not invoke `decode` or `decode_eof` again, until data can be read
/// during a retry.
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/io/stream_reader.rs
Expand Up @@ -93,7 +93,7 @@ where
}

/// Consumes this `StreamReader`, returning a Tuple consisting
/// of the underlying stream and an Option of the interal buffer,
/// of the underlying stream and an Option of the internal buffer,
/// which is Some in case the buffer contains elements.
pub fn into_inner_with_chunk(self) -> (S, Option<B>) {
if self.has_chunk() {
Expand Down
6 changes: 3 additions & 3 deletions tokio/CHANGELOG.md
Expand Up @@ -1235,7 +1235,7 @@ Biggest changes are:
- Feature flags are simplified
- `rt-core` and `rt-util` are combined to `rt`
- `rt-threaded` is renamed to `rt-multi-thread` to match builder API
- `tcp`, `udp`, `uds`, `dns` are combied to `net`.
- `tcp`, `udp`, `uds`, `dns` are combined to `net`.
- `parking_lot` is included with `full`

### Changes
Expand Down Expand Up @@ -1733,7 +1733,7 @@ Biggest changes are:
- `net::lookup_host` maps a `T: ToSocketAddrs` to a stream of `SocketAddrs` ([#1870]).
- `process::Child` fields are made public to match `std` ([#2014]).
- impl `Stream` for `sync::broadcast::Receiver` ([#2012]).
- `sync::RwLock` provides an asynchonous read-write lock ([#1699]).
- `sync::RwLock` provides an asynchronous read-write lock ([#1699]).
- `runtime::Handle::current` returns the handle for the current runtime ([#2040]).
- `StreamExt::filter` filters stream values according to a predicate ([#2001]).
- `StreamExt::filter_map` simultaneously filter and map stream values ([#2001]).
Expand Down Expand Up @@ -1842,7 +1842,7 @@ Biggest changes are:
### Fixes

- calling `spawn_blocking` after runtime shutdown ([#1875]).
- `LocalSet` drop inifinite loop ([#1892]).
- `LocalSet` drop infinite loop ([#1892]).
- `LocalSet` hang under load ([#1905]).
- improved documentation ([#1865], [#1866], [#1868], [#1874], [#1876], [#1911]).

Expand Down
14 changes: 13 additions & 1 deletion tokio/Cargo.toml
Expand Up @@ -52,7 +52,12 @@ net = [
"mio/os-ext",
"mio/net",
"socket2",
"winapi/fileapi",
"winapi/handleapi",
"winapi/namedpipeapi",
"winapi/winbase",
"winapi/winnt",
"winapi/minwindef",
]
process = [
"bytes",
Expand All @@ -62,7 +67,12 @@ process = [
"mio/os-ext",
"mio/net",
"signal-hook-registry",
"winapi/handleapi",
"winapi/processthreadsapi",
"winapi/threadpoollegacyapiset",
"winapi/winbase",
"winapi/winnt",
"winapi/minwindef",
]
# Includes basic task execution capabilities
rt = ["once_cell"]
Expand All @@ -78,6 +88,8 @@ signal = [
"mio/os-ext",
"signal-hook-registry",
"winapi/consoleapi",
"winapi/wincon",
"winapi/minwindef",
]
sync = []
test-util = ["rt", "sync", "time"]
Expand Down Expand Up @@ -118,7 +130,7 @@ nix = { version = "0.24", default-features = false, features = ["fs", "socket"]
[target.'cfg(windows)'.dependencies.winapi]
version = "0.3.8"
default-features = false
features = ["std", "winsock2", "mswsock", "handleapi", "ws2ipdef", "ws2tcpip"]
features = ["std"]
optional = true

[target.'cfg(windows)'.dev-dependencies.ntapi]
Expand Down
18 changes: 18 additions & 0 deletions tokio/src/fs/mod.rs
Expand Up @@ -22,6 +22,24 @@
//! `std::io::ErrorKind::WouldBlock` if a *worker* thread can not be converted
//! to a *backup* thread immediately.
//!
//! **Warning**: These adapters may create a large number of temporary tasks,
//! especially when reading large files. When performing a lot of operations
//! in one batch, it may be significantly faster to use [`spawn_blocking`]
//! directly:
//!
//! ```
//! use tokio::fs::File;
//! use std::io::{BufReader, BufRead};
//! async fn count_lines(file: File) -> Result<usize, std::io::Error> {
//! let file = file.into_std().await;
//! tokio::task::spawn_blocking(move || {
//! let line_count = BufReader::new(file).lines().count();
//! Ok(line_count)
//! }).await?
//! }
//! ```
//!
//! [`spawn_blocking`]: fn@crate::task::spawn_blocking
//! [`AsyncRead`]: trait@crate::io::AsyncRead

mod canonicalize;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/park/mod.rs
Expand Up @@ -85,7 +85,7 @@ pub(crate) trait Park {
/// `Park` implementation.
fn park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error>;

/// Releases all resources holded by the parker for proper leak-free shutdown.
/// Releases all resources held by the parker for proper leak-free shutdown.
fn shutdown(&mut self);
}

Expand Down

0 comments on commit a2007ac

Please sign in to comment.