on master help sign in
Remove select_all implementation
commitd55419604c7fa3d3b0559cf985760170a3866d87 authorEgor Karavaev <batonius.kirov@gmail.com> dateThu 3 Jun 2021, 19:48 (5 years ago) parent29b9eed
2 files changed+2−146
helix-lsp/src/lib.rs+2−3 helix-lsp/src/select_all.rs−143
helix-lsp/src/lib.rs+2−3
@@ -1,5 +1,4 @@
11mod client;
2−mod select_all;
32mod transport;
43
54pub use jsonrpc_core as jsonrpc;
@@ -171,7 +170,7 @@ pub use jsonrpc::Call;
171170
172171type LanguageId = String;
173172
174−use crate::select_all::SelectAll;
173+use futures_util::stream::select_all::SelectAll;
175174
176175pub struct Registry {
177176 inner: HashMap<LanguageId, Option<Arc<Client>>>,
@@ -198,7 +197,7 @@ impl Registry {
198197 if let Some(config) = &language_config.language_server {
199198 // avoid borrow issues
200199 let inner = &mut self.inner;
201− let s_incoming = &self.incoming;
200+ let s_incoming = &mut self.incoming;
202201
203202 let language_server = inner
204203 .entry(language_config.scope.clone()) // can't use entry with Borrow keys: https://github.com/rust-lang/rfcs/pull/1769
helix-lsp/src/select_all.rsdeleted−143
@@ -1,143 +0,0 @@
1−//! An unbounded set of streams
2−
3−use core::{
4− fmt::{self, Debug},
5− iter::FromIterator,
6− pin::Pin,
7−};
8−
9−use std::task::{Context, Poll};
10−
11−use futures_util::stream::{FusedStream, FuturesUnordered, StreamExt, StreamFuture};
12−use futures_util::{ready, stream::Stream};
13−
14−/// An unbounded set of streams
15−///
16−/// This "combinator" provides the ability to maintain a set of streams
17−/// and drive them all to completion.
18−///
19−/// Streams are pushed into this set and their realized values are
20−/// yielded as they become ready. Streams will only be polled when they
21−/// generate notifications. This allows to coordinate a large number of streams.
22−///
23−/// Note that you can create a ready-made `SelectAll` via the
24−/// `select_all` function in the `stream` module, or you can start with an
25−/// empty set with the `SelectAll::new` constructor.
26−#[must_use = "streams do nothing unless polled"]
27−pub struct SelectAll<St> {
28− inner: FuturesUnordered<StreamFuture<St>>,
29−}
30−
31−impl<St: Debug> Debug for SelectAll<St> {
32− fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33− write!(f, "SelectAll {{ ... }}")
34− }
35−}
36−
37−impl<St: Stream + Unpin> SelectAll<St> {
38− /// Constructs a new, empty `SelectAll`
39− ///
40− /// The returned `SelectAll` does not contain any streams and, in this
41− /// state, `SelectAll::poll` will return `Poll::Ready(None)`.
42− pub fn new() -> Self {
43− Self {
44− inner: FuturesUnordered::new(),
45− }
46− }
47−
48− /// Returns the number of streams contained in the set.
49− ///
50− /// This represents the total number of in-flight streams.
51− pub fn len(&self) -> usize {
52− self.inner.len()
53− }
54−
55− /// Returns `true` if the set contains no streams
56− pub fn is_empty(&self) -> bool {
57− self.inner.is_empty()
58− }
59−
60− /// Push a stream into the set.
61− ///
62− /// This function submits the given stream to the set for managing. This
63− /// function will not call `poll` on the submitted stream. The caller must
64− /// ensure that `SelectAll::poll` is called in order to receive task
65− /// notifications.
66− pub fn push(&self, stream: St) {
67− self.inner.push(stream.into_future());
68− }
69−}
70−
71−impl<St: Stream + Unpin> Default for SelectAll<St> {
72− fn default() -> Self {
73− Self::new()
74− }
75−}
76−
77−impl<St: Stream + Unpin> Stream for SelectAll<St> {
78− type Item = St::Item;
79−
80− fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
81− loop {
82− match ready!(self.inner.poll_next_unpin(cx)) {
83− Some((Some(item), remaining)) => {
84− self.push(remaining);
85− return Poll::Ready(Some(item));
86− }
87− Some((None, _)) => {
88− // `FuturesUnordered` thinks it isn't terminated
89− // because it yielded a Some.
90− // We do not return, but poll `FuturesUnordered`
91− // in the next loop iteration.
92− }
93− None => return Poll::Ready(None),
94− }
95− }
96− }
97−}
98−
99−impl<St: Stream + Unpin> FusedStream for SelectAll<St> {
100− fn is_terminated(&self) -> bool {
101− self.inner.is_terminated()
102− }
103−}
104−
105−/// Convert a list of streams into a `Stream` of results from the streams.
106−///
107−/// This essentially takes a list of streams (e.g. a vector, an iterator, etc.)
108−/// and bundles them together into a single stream.
109−/// The stream will yield items as they become available on the underlying
110−/// streams internally, in the order they become available.
111−///
112−/// Note that the returned set can also be used to dynamically push more
113−/// futures into the set as they become available.
114−///
115−/// This function is only available when the `std` or `alloc` feature of this
116−/// library is activated, and it is activated by default.
117−pub fn select_all<I>(streams: I) -> SelectAll<I::Item>
118−where
119− I: IntoIterator,
120− I::Item: Stream + Unpin,
121−{
122− let set = SelectAll::new();
123−
124− for stream in streams {
125− set.push(stream);
126− }
127−
128− set
129−}
130−
131−impl<St: Stream + Unpin> FromIterator<St> for SelectAll<St> {
132− fn from_iter<T: IntoIterator<Item = St>>(iter: T) -> Self {
133− select_all(iter)
134− }
135−}
136−
137−impl<St: Stream + Unpin> Extend<St> for SelectAll<St> {
138− fn extend<T: IntoIterator<Item = St>>(&mut self, iter: T) {
139− for st in iter {
140− self.push(st)
141− }
142− }
143−}