mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-27 00:00:12 +02:00
ci: unfreeze wasm tests from rustc 1.88.0 (#7537)
This commit is contained in:
@@ -36,28 +36,28 @@ use tokio::task::{AbortHandle, Id, JoinError, JoinSet, LocalSet};
|
||||
/// ```
|
||||
/// use tokio_util::task::JoinMap;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let mut map = JoinMap::new();
|
||||
/// # #[tokio::main(flavor = "current_thread")]
|
||||
/// # async fn main() {
|
||||
/// let mut map = JoinMap::new();
|
||||
///
|
||||
/// for i in 0..10 {
|
||||
/// // Spawn a task on the `JoinMap` with `i` as its key.
|
||||
/// map.spawn(i, async move { /* ... */ });
|
||||
/// }
|
||||
///
|
||||
/// let mut seen = [false; 10];
|
||||
///
|
||||
/// // When a task completes, `join_next` returns the task's key along
|
||||
/// // with its output.
|
||||
/// while let Some((key, res)) = map.join_next().await {
|
||||
/// seen[key] = true;
|
||||
/// assert!(res.is_ok(), "task {} completed successfully!", key);
|
||||
/// }
|
||||
///
|
||||
/// for i in 0..10 {
|
||||
/// assert!(seen[i]);
|
||||
/// }
|
||||
/// for i in 0..10 {
|
||||
/// // Spawn a task on the `JoinMap` with `i` as its key.
|
||||
/// map.spawn(i, async move { /* ... */ });
|
||||
/// }
|
||||
///
|
||||
/// let mut seen = [false; 10];
|
||||
///
|
||||
/// // When a task completes, `join_next` returns the task's key along
|
||||
/// // with its output.
|
||||
/// while let Some((key, res)) = map.join_next().await {
|
||||
/// seen[key] = true;
|
||||
/// assert!(res.is_ok(), "task {} completed successfully!", key);
|
||||
/// }
|
||||
///
|
||||
/// for i in 0..10 {
|
||||
/// assert!(seen[i]);
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// Cancel tasks based on their keys:
|
||||
@@ -65,30 +65,30 @@ use tokio::task::{AbortHandle, Id, JoinError, JoinSet, LocalSet};
|
||||
/// ```
|
||||
/// use tokio_util::task::JoinMap;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let mut map = JoinMap::new();
|
||||
/// # #[tokio::main(flavor = "current_thread")]
|
||||
/// # async fn main() {
|
||||
/// let mut map = JoinMap::new();
|
||||
///
|
||||
/// map.spawn("hello world", std::future::ready(1));
|
||||
/// map.spawn("goodbye world", std::future::pending());
|
||||
/// map.spawn("hello world", std::future::ready(1));
|
||||
/// map.spawn("goodbye world", std::future::pending());
|
||||
///
|
||||
/// // Look up the "goodbye world" task in the map and abort it.
|
||||
/// let aborted = map.abort("goodbye world");
|
||||
/// // Look up the "goodbye world" task in the map and abort it.
|
||||
/// let aborted = map.abort("goodbye world");
|
||||
///
|
||||
/// // `JoinMap::abort` returns `true` if a task existed for the
|
||||
/// // provided key.
|
||||
/// assert!(aborted);
|
||||
/// // `JoinMap::abort` returns `true` if a task existed for the
|
||||
/// // provided key.
|
||||
/// assert!(aborted);
|
||||
///
|
||||
/// while let Some((key, res)) = map.join_next().await {
|
||||
/// if key == "goodbye world" {
|
||||
/// // The aborted task should complete with a cancelled `JoinError`.
|
||||
/// assert!(res.unwrap_err().is_cancelled());
|
||||
/// } else {
|
||||
/// // Other tasks should complete normally.
|
||||
/// assert_eq!(res.unwrap(), 1);
|
||||
/// }
|
||||
/// while let Some((key, res)) = map.join_next().await {
|
||||
/// if key == "goodbye world" {
|
||||
/// // The aborted task should complete with a cancelled `JoinError`.
|
||||
/// assert!(res.unwrap_err().is_cancelled());
|
||||
/// } else {
|
||||
/// // Other tasks should complete normally.
|
||||
/// assert_eq!(res.unwrap(), 1);
|
||||
/// }
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// [`JoinSet`]: tokio::task::JoinSet
|
||||
@@ -186,7 +186,7 @@ impl<K, V, S> JoinMap<K, V, S> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[tokio::main]
|
||||
/// # #[tokio::main(flavor = "current_thread")]
|
||||
/// # async fn main() {
|
||||
/// use tokio_util::task::JoinMap;
|
||||
/// use std::collections::hash_map::RandomState;
|
||||
@@ -521,7 +521,7 @@ where
|
||||
/// ```
|
||||
/// use tokio_util::task::JoinMap;
|
||||
///
|
||||
/// # #[tokio::main]
|
||||
/// # #[tokio::main(flavor = "current_thread")]
|
||||
/// # async fn main() {
|
||||
/// let mut map = JoinMap::new();
|
||||
///
|
||||
@@ -686,7 +686,7 @@ where
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[tokio::main]
|
||||
/// # #[tokio::main(flavor = "current_thread")]
|
||||
/// # async fn main() {
|
||||
/// use tokio_util::task::JoinMap;
|
||||
///
|
||||
@@ -715,7 +715,7 @@ where
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[tokio::main]
|
||||
/// # #[tokio::main(flavor = "current_thread")]
|
||||
/// # async fn main() {
|
||||
/// use tokio_util::task::JoinMap;
|
||||
///
|
||||
|
||||
@@ -22,6 +22,8 @@ use tokio::task::{spawn_local, JoinHandle, LocalSet};
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(not(target_family = "wasm"))]
|
||||
/// # {
|
||||
/// use std::rc::Rc;
|
||||
/// use tokio::task;
|
||||
/// use tokio_util::task::LocalPoolHandle;
|
||||
@@ -45,6 +47,7 @@ use tokio::task::{spawn_local, JoinHandle, LocalSet};
|
||||
/// }).await.unwrap();
|
||||
/// println!("output: {}", output);
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
#[derive(Clone)]
|
||||
@@ -94,6 +97,8 @@ impl LocalPoolHandle {
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// # #[cfg(not(target_family = "wasm"))]
|
||||
/// # {
|
||||
/// use std::rc::Rc;
|
||||
/// use tokio_util::task::LocalPoolHandle;
|
||||
///
|
||||
@@ -116,6 +121,7 @@ impl LocalPoolHandle {
|
||||
///
|
||||
/// assert_eq!(output, "test");
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn spawn_pinned<F, Fut>(&self, create_task: F) -> JoinHandle<Fut::Output>
|
||||
where
|
||||
@@ -144,6 +150,8 @@ impl LocalPoolHandle {
|
||||
/// This method can be used to spawn a task on all worker threads of the pool:
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(not(target_family = "wasm"))]
|
||||
/// # {
|
||||
/// use tokio_util::task::LocalPoolHandle;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
@@ -167,6 +175,7 @@ impl LocalPoolHandle {
|
||||
/// handle.await.unwrap();
|
||||
/// }
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
#[track_caller]
|
||||
|
||||
@@ -66,23 +66,23 @@ use tokio::{
|
||||
/// ```
|
||||
/// use tokio_util::task::TaskTracker;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let tracker = TaskTracker::new();
|
||||
/// # #[tokio::main(flavor = "current_thread")]
|
||||
/// # async fn main() {
|
||||
/// let tracker = TaskTracker::new();
|
||||
///
|
||||
/// for i in 0..10 {
|
||||
/// tracker.spawn(async move {
|
||||
/// println!("Task {} is running!", i);
|
||||
/// });
|
||||
/// }
|
||||
/// // Once we spawned everything, we close the tracker.
|
||||
/// tracker.close();
|
||||
///
|
||||
/// // Wait for everything to finish.
|
||||
/// tracker.wait().await;
|
||||
///
|
||||
/// println!("This is printed after all of the tasks.");
|
||||
/// for i in 0..10 {
|
||||
/// tracker.spawn(async move {
|
||||
/// println!("Task {} is running!", i);
|
||||
/// });
|
||||
/// }
|
||||
/// // Once we spawned everything, we close the tracker.
|
||||
/// tracker.close();
|
||||
///
|
||||
/// // Wait for everything to finish.
|
||||
/// tracker.wait().await;
|
||||
///
|
||||
/// println!("This is printed after all of the tasks.");
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// ## Wait for tasks to exit
|
||||
|
||||
Reference in New Issue
Block a user