Skip to content

Commit 9246a94

Browse files
authored
Merge pull request #187 from conradludgate/fix-pin-violation
fix pin violation in much of concurrentstream
2 parents 629ddf3 + 00601b9 commit 9246a94

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ futures-lite = "1.12.0"
3838
pin-project = "1.0.8"
3939
slab = { version = "0.4.8", optional = true }
4040
smallvec = { version = "1.11.0", optional = true }
41+
futures-buffered = "0.2.6"
4142

4243
[dev-dependencies]
4344
async-io = "2.3.2"

src/concurrent_stream/for_each.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{Consumer, ConsumerState};
2-
use crate::future::FutureGroup;
2+
use futures_buffered::FuturesUnordered;
33
use futures_lite::StreamExt;
44
use pin_project::pin_project;
55

@@ -22,7 +22,7 @@ where
2222
// NOTE: we can remove the `Arc` here if we're willing to make this struct self-referential
2323
count: Arc<AtomicUsize>,
2424
#[pin]
25-
group: FutureGroup<ForEachFut<F, FutT, T, FutB>>,
25+
group: FuturesUnordered<ForEachFut<F, FutT, T, FutB>>,
2626
limit: usize,
2727
f: F,
2828
_phantom: PhantomData<(T, FutB)>,
@@ -44,7 +44,7 @@ where
4444
f,
4545
_phantom: PhantomData,
4646
count: Arc::new(AtomicUsize::new(0)),
47-
group: FutureGroup::new(),
47+
group: FuturesUnordered::new(),
4848
}
4949
}
5050
}
@@ -69,7 +69,7 @@ where
6969
// Space was available! - insert the item for posterity
7070
this.count.fetch_add(1, Ordering::Relaxed);
7171
let fut = ForEachFut::new(this.f.clone(), future, this.count.clone());
72-
this.group.as_mut().insert_pinned(fut);
72+
this.group.as_mut().push(fut);
7373

7474
ConsumerState::Continue
7575
}

src/concurrent_stream/from_concurrent_stream.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use super::{ConcurrentStream, Consumer, ConsumerState, IntoConcurrentStream};
2-
use crate::future::FutureGroup;
32
#[cfg(all(feature = "alloc", not(feature = "std")))]
43
use alloc::vec::Vec;
54
use core::future::Future;
65
use core::pin::Pin;
6+
use futures_buffered::FuturesUnordered;
77
use futures_lite::StreamExt;
88
use pin_project::pin_project;
99

@@ -32,14 +32,14 @@ impl<T> FromConcurrentStream<T> for Vec<T> {
3232
#[pin_project]
3333
pub(crate) struct VecConsumer<'a, Fut: Future> {
3434
#[pin]
35-
group: FutureGroup<Fut>,
35+
group: FuturesUnordered<Fut>,
3636
output: &'a mut Vec<Fut::Output>,
3737
}
3838

3939
impl<'a, Fut: Future> VecConsumer<'a, Fut> {
4040
pub(crate) fn new(output: &'a mut Vec<Fut::Output>) -> Self {
4141
Self {
42-
group: FutureGroup::new(),
42+
group: FuturesUnordered::new(),
4343
output,
4444
}
4545
}
@@ -54,7 +54,7 @@ where
5454
async fn send(self: Pin<&mut Self>, future: Fut) -> super::ConsumerState {
5555
let mut this = self.project();
5656
// unbounded concurrency, so we just goooo
57-
this.group.as_mut().insert_pinned(future);
57+
this.group.as_mut().push(future);
5858
ConsumerState::Continue
5959
}
6060

src/concurrent_stream/try_for_each.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::concurrent_stream::ConsumerState;
2-
use crate::future::FutureGroup;
32
use crate::private::Try;
3+
use futures_buffered::FuturesUnordered;
44
use futures_lite::StreamExt;
55
use pin_project::pin_project;
66

@@ -26,7 +26,7 @@ where
2626
count: Arc<AtomicUsize>,
2727
// TODO: remove the `Pin<Box>` from this signature by requiring this struct is pinned
2828
#[pin]
29-
group: FutureGroup<TryForEachFut<F, FutT, T, FutB, B>>,
29+
group: FuturesUnordered<TryForEachFut<F, FutT, T, FutB, B>>,
3030
limit: usize,
3131
residual: Option<B::Residual>,
3232
f: F,
@@ -50,7 +50,7 @@ where
5050
f,
5151
residual: None,
5252
count: Arc::new(AtomicUsize::new(0)),
53-
group: FutureGroup::new(),
53+
group: FuturesUnordered::new(),
5454
_phantom: PhantomData,
5555
}
5656
}
@@ -93,7 +93,7 @@ where
9393
// Space was available! - insert the item for posterity
9494
this.count.fetch_add(1, Ordering::Relaxed);
9595
let fut = TryForEachFut::new(this.f.clone(), future, this.count.clone());
96-
this.group.as_mut().insert_pinned(fut);
96+
this.group.as_mut().push(fut);
9797
ConsumerState::Continue
9898
}
9999

src/future/future_group.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ impl<F: Future> FutureGroup<F> {
274274
Key(index)
275275
}
276276

277+
#[allow(unused)]
277278
/// Insert a value into a pinned `FutureGroup`
278279
///
279280
/// This method is private because it serves as an implementation detail for

0 commit comments

Comments
 (0)