File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff 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/// ```
678681impl < T , F > std:: iter:: Extend < F > for JoinSet < T >
679682where
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 } ) ;
Original file line number Diff line number Diff 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+
407424mod spawn_local {
408425 use super :: * ;
409426
You can’t perform that action at this time.
0 commit comments