1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// use std::{cell::UnsafeCell, future::Future, mem, pin::Pin, task::Poll};
//
// /// Select naive is iterating through the futures in order in which they exist in the vector
// pub async fn select_naive<T, F, Fut>(futs: Vec<(Fut, Option<F>)>)
// where
// T: Send,
// F: Fn(&T),
// Fut: Future<Output = T> + Send,
// {
// let capacity = futs.capacity();
// let select = SelectNaive {
// futs: futs
// .into_iter()
// .map(|(fut, callback)| Futs {
// fut: UnsafeCell::new(Box::pin(fut)),
// fn_: callback,
// })
// .collect(),
// };
// }
//
// struct Futs<T, F, Fut>
// where
// T: Send,
// F: Fn(&T),
// Fut: Future<Output = T> + Send,
// {
// fut: UnsafeCell<Pin<Box<Fut>>>,
// fn_: Option<F>,
// }
//
// // #[derive(Debug)]
// struct SelectNaive<Fut, F, T>
// where
// T: Send,
// F: Fn(&T),
// Fut: Future<Output = T> + Send,
// {
// futs: Vec<Futs<T, F, Fut>>,
// }
//
// impl<Fut, F, T> Future for SelectNaive<Fut, F, T>
// where
// T: Send,
// F: Fn(T),
// Fut: Future<Output = T> + Send,
// {
// type Output = ();
//
// fn poll(
// mut self: std::pin::Pin<&mut Self>,
// cx: &mut std::task::Context<'_>,
// ) -> std::task::Poll<Self::Output> {
// for fut in self.futs.iter() {
// let original_future = unsafe { &mut *fut.fut.get() };
//
// let p_fut = async { std::future::pending::<T>().await };
// let mut placeholder_fut = Box::pin(p_fut);
// let fut_to_poll = mem::replace(original_future, placeholder_fut);
//
// let poll_result = fut_to_poll.as_mut().poll(cx);
//
// *original_future = fut_to_poll;
//
// let Poll::Ready(result) = poll_result else {
// continue;
// };
//
// if let Some(callback) = &fut.fn_ {
// callback(result);
// }
//
// return Poll::Ready(());
// }
// Poll::Pending
// }
// }