Skip to content

Commit baa8c74

Browse files
Add MappedFutures
1 parent 3ce1fca commit baa8c74

File tree

5 files changed

+594
-0
lines changed

5 files changed

+594
-0
lines changed

futures-util/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ spin = { version = "0.10.0", optional = true }
4848
futures = { path = "../futures", features = ["async-await", "thread-pool"] }
4949
futures-test = { path = "../futures-test" }
5050
tokio = "0.1.11"
51+
futures-timer = "3.0.3"
5152

5253
[package.metadata.docs.rs]
5354
all-features = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! An unbounded map of futures.
2+
//!
3+
//! This module is only available when the `std` or `alloc` feature of this
4+
//! library is activated, and it is activated by default.
5+
6+
use crate::task::AtomicWaker;
7+
use alloc::sync::{Arc, Weak};
8+
use core::cell::UnsafeCell;
9+
use core::fmt::{self, Debug};
10+
use core::iter::FromIterator;
11+
use core::marker::PhantomData;
12+
use core::mem;
13+
use core::pin::Pin;
14+
use core::ptr;
15+
use core::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release, SeqCst};
16+
use core::sync::atomic::{AtomicBool, AtomicPtr};
17+
use futures_core::future::Future;
18+
use futures_core::stream::{FusedStream, Stream};
19+
use futures_core::task::{Context, Poll};
20+
use futures_task::{FutureObj, LocalFutureObj, LocalSpawn, Spawn, SpawnError};
21+
use std::collections::{HashMap, HashSet};
22+
23+
use super::FuturesUnordered;

futures-util/src/stream/futures_unordered/iter.rs

+28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::task::Task;
22
use super::FuturesUnordered;
3+
use core::hash::Hash;
34
use core::marker::PhantomData;
45
use core::pin::Pin;
56
use core::ptr;
@@ -13,6 +14,19 @@ pub struct IterPinMut<'a, Fut> {
1314
pub(super) _marker: PhantomData<&'a mut FuturesUnordered<Fut>>,
1415
}
1516

17+
/// Mutable iterator over all keys and futures in the map.
18+
// #[derive(Debug)]
19+
// pub struct MapIterPinMut<'a, K, Fut> {
20+
// pub(super) inner: IterMut<'a, K, Fut>,
21+
// // pub(super) task: *const Task<Fut>,
22+
// // pub(super) len: usize,
23+
// // pub(super) _marker: PhantomData<&'a mut FuturesUnordered<Fut>>,
24+
// }
25+
26+
/// Immutable iterator over all the keys and futures in the map.
27+
// #[derive(Debug)]
28+
// pub struct IterMap<'a, K: Hash + Eq, Fut: Unpin>(pub(super) IterPinRef<'a, K, Fut>);
29+
1630
/// Mutable iterator over all futures in the unordered set.
1731
#[derive(Debug)]
1832
pub struct IterMut<'a, Fut: Unpin>(pub(super) IterPinMut<'a, Fut>);
@@ -26,6 +40,20 @@ pub struct IterPinRef<'a, Fut> {
2640
pub(super) _marker: PhantomData<&'a FuturesUnordered<Fut>>,
2741
}
2842

43+
/// Immutable iterator over all keys and futures in the map.
44+
// #[derive(Debug)]
45+
// pub struct MapIterPinRef<'a, K, Fut> {
46+
// inner: HashMapIter<'a, K, *const Task<Fut>>,
47+
// // pub(super) task: *const Task<Fut>,
48+
// // pub(super) len: usize,
49+
// // pub(super) pending_next_all: *mut Task<Fut>,
50+
// // pub(super) _marker: PhantomData<&'a FuturesUnordered<Fut>>,
51+
// }
52+
53+
/// Immutable iterator over all keys and futures in the map.
54+
// #[derive(Debug)]
55+
// pub struct MapIter<'a, K, Fut>(pub(super) MapIterPinRef<'a, K, Fut>);
56+
2957
/// Immutable iterator over all the futures in the unordered set.
3058
#[derive(Debug)]
3159
pub struct Iter<'a, Fut: Unpin>(pub(super) IterPinRef<'a, Fut>);

0 commit comments

Comments
 (0)