forked from Orchid/orchid
RA leaks memory in code-server, switching back to desktop
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use futures::FutureExt;
|
||||
use async_stream::stream;
|
||||
use futures::future::{LocalBoxFuture, join_all};
|
||||
use futures::{FutureExt, Stream, StreamExt, pin_mut};
|
||||
use itertools::Itertools;
|
||||
use orchid_api::ResolveNames;
|
||||
use orchid_base::error::{OrcRes, Reporter};
|
||||
@@ -171,16 +172,31 @@ pub struct ConstCtx {
|
||||
constid: api::ParsedConstId,
|
||||
}
|
||||
impl ConstCtx {
|
||||
pub async fn names<const N: usize>(&self, names: [&Sym; N]) -> [Option<Sym>; N] {
|
||||
pub fn names<'a>(
|
||||
&'a self,
|
||||
names: impl IntoIterator<Item = &'a Sym> + Clone + 'a,
|
||||
) -> impl Stream<Item = (Sym, Option<Sym>)> + 'a {
|
||||
let resolve_names = ResolveNames {
|
||||
constid: self.constid,
|
||||
sys: self.ctx.sys_id(),
|
||||
names: names.into_iter().map(|n| n.to_api()).collect_vec(),
|
||||
names: names.clone().into_iter().map(|n| n.to_api()).collect_vec(),
|
||||
};
|
||||
let names = self.ctx.reqnot().request(resolve_names).await;
|
||||
stream! {
|
||||
let new_names = self.ctx.reqnot().request(resolve_names).await;
|
||||
for (name, name_opt) in names.into_iter().zip(new_names) {
|
||||
yield (name.clone(), match name_opt {
|
||||
None => None,
|
||||
Some(name) => Some(Sym::from_api(name, self.ctx.i()).await)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
pub async fn names_n<const N: usize>(&self, names: [&Sym; N]) -> [Option<Sym>; N] {
|
||||
let mut results = [const { None }; N];
|
||||
for (i, name) in names.into_iter().enumerate().filter_map(|(i, n)| Some((i, n?))) {
|
||||
results[i] = Some(Sym::from_api(name, self.ctx.i()).await);
|
||||
let names = self.names(names).enumerate().filter_map(|(i, n)| async move { Some((i, n.1?)) });
|
||||
pin_mut!(names);
|
||||
while let Some((i, name)) = names.next().await {
|
||||
results[i] = Some(name);
|
||||
}
|
||||
results
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user