23
23
// NOTE: we can remove the `Arc` here if we're willing to make this struct self-referential
24
24
count : Arc < AtomicUsize > ,
25
25
#[ pin]
26
- group : Pin < Box < FutureGroup < ForEachFut < F , FutT , T , FutB > > > > ,
26
+ group : FutureGroup < ForEachFut < F , FutT , T , FutB > > ,
27
27
limit : usize ,
28
28
f : F ,
29
29
_phantom : PhantomData < ( T , FutB ) > ,
45
45
f,
46
46
_phantom : PhantomData ,
47
47
count : Arc :: new ( AtomicUsize :: new ( 0 ) ) ,
48
- group : Box :: pin ( FutureGroup :: new ( ) ) ,
48
+ group : FutureGroup :: new ( ) ,
49
49
}
50
50
}
51
51
}
@@ -60,30 +60,33 @@ where
60
60
{
61
61
type Output = ( ) ;
62
62
63
- async fn send ( & mut self , future : FutT ) -> super :: ConsumerState {
63
+ async fn send ( mut self : Pin < & mut Self > , future : FutT ) -> super :: ConsumerState {
64
+ let mut this = self . project ( ) ;
64
65
// If we have no space, we're going to provide backpressure until we have space
65
- while self . count . load ( Ordering :: Relaxed ) >= self . limit {
66
- self . group . next ( ) . await ;
66
+ while this . count . load ( Ordering :: Relaxed ) >= * this . limit {
67
+ this . group . next ( ) . await ;
67
68
}
68
69
69
70
// Space was available! - insert the item for posterity
70
- self . count . fetch_add ( 1 , Ordering :: Relaxed ) ;
71
- let fut = ForEachFut :: new ( self . f . clone ( ) , future, self . count . clone ( ) ) ;
72
- self . group . as_mut ( ) . insert_pinned ( fut) ;
71
+ this . count . fetch_add ( 1 , Ordering :: Relaxed ) ;
72
+ let fut = ForEachFut :: new ( this . f . clone ( ) , future, this . count . clone ( ) ) ;
73
+ this . group . as_mut ( ) . insert_pinned ( fut) ;
73
74
74
75
ConsumerState :: Continue
75
76
}
76
77
77
- async fn progress ( & mut self ) -> super :: ConsumerState {
78
- while let Some ( _) = self . group . next ( ) . await { }
78
+ async fn progress ( self : Pin < & mut Self > ) -> super :: ConsumerState {
79
+ let mut this = self . project ( ) ;
80
+ while let Some ( _) = this. group . next ( ) . await { }
79
81
ConsumerState :: Empty
80
82
}
81
83
82
- async fn flush ( & mut self ) -> Self :: Output {
84
+ async fn flush ( self : Pin < & mut Self > ) -> Self :: Output {
85
+ let mut this = self . project ( ) ;
83
86
// 4. We will no longer receive any additional futures from the
84
87
// underlying stream; wait until all the futures in the group have
85
88
// resolved.
86
- while let Some ( _) = self . group . next ( ) . await { }
89
+ while let Some ( _) = this . group . next ( ) . await { }
87
90
}
88
91
}
89
92
0 commit comments