Skip to content

Commit 43f66fe

Browse files
committed
Exclude the JoinSet::extend doc test for WASM
Add the doc test as IT test too
1 parent 7326d58 commit 43f66fe

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

tokio/src/task/join_set.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,8 @@ where
656656
/// # Examples
657657
///
658658
/// ```
659+
/// # #[cfg(not(target_family = "wasm"))]
660+
/// # {
659661
/// use tokio::task::JoinSet;
660662
///
661663
/// #[tokio::main]
@@ -674,14 +676,18 @@ where
674676
/// assert!(seen[i]);
675677
/// }
676678
/// }
679+
/// # }
677680
/// ```
678681
impl<T, F> std::iter::Extend<F> for JoinSet<T>
679682
where
680683
F: Future<Output = T>,
681684
F: Send + 'static,
682685
T: Send + 'static,
683686
{
684-
fn extend<I: IntoIterator<Item = F>>(&mut self, iter: I) {
687+
fn extend<I>(&mut self, iter: I)
688+
where
689+
I: IntoIterator<Item = F>,
690+
{
685691
iter.into_iter().for_each(|task| {
686692
self.spawn(task);
687693
});

tokio/tests/task_join_set.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,23 @@ async fn try_join_next_with_id() {
404404
assert_eq!(joined, spawned);
405405
}
406406

407+
#[tokio::test]
408+
async fn extend() {
409+
let mut set: JoinSet<_> = (0..5).map(|i| async move { i }).collect();
410+
411+
set.extend((5..10).map(|i| async move { i }));
412+
413+
let mut seen = [false; 10];
414+
while let Some(res) = set.join_next().await {
415+
let idx = res.unwrap();
416+
seen[idx] = true;
417+
}
418+
419+
for i in 0..10 {
420+
assert!(seen[i]);
421+
}
422+
}
423+
407424
mod spawn_local {
408425
use super::*;
409426

0 commit comments

Comments
 (0)