|
|
use anyhow::Result; |
|
|
|
|
|
use crate::{self as turbo_tasks, RawVc, ResolvedVc, TryJoinIterExt, Vc}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[turbo_tasks::value(cell = "new", eq = "manual")] |
|
|
#[derive(Debug)] |
|
|
pub struct Completion; |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl Completion { |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub fn immutable() -> Vc<Self> { |
|
|
Completion::cell(Completion) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Completion { |
|
|
|
|
|
pub fn new() -> Vc<Self> { |
|
|
Completion::cell(Completion) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn unchanged() -> Vc<Self> { |
|
|
|
|
|
|
|
|
|
|
|
let cell = turbo_tasks::macro_helpers::find_cell_by_type( |
|
|
<Completion as crate::VcValueType>::get_value_type_id(), |
|
|
); |
|
|
cell.conditional_update(|old| old.is_none().then_some(Completion)); |
|
|
let raw: RawVc = cell.into(); |
|
|
raw.into() |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value(transparent)] |
|
|
pub struct Completions(Vec<ResolvedVc<Completion>>); |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl Completions { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub fn all(completions: Vec<ResolvedVc<Completion>>) -> Vc<Completion> { |
|
|
Vc::<Completions>::cell(completions).completed() |
|
|
} |
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn completed(&self) -> anyhow::Result<Vc<Completion>> { |
|
|
if self.0.len() > 100 { |
|
|
let mid = self.0.len() / 2; |
|
|
let (left, right) = self.0.split_at(mid); |
|
|
let left = Vc::<Completions>::cell(left.to_vec()); |
|
|
let right = Vc::<Completions>::cell(right.to_vec()); |
|
|
let left = left.completed(); |
|
|
let right = right.completed(); |
|
|
left.await?; |
|
|
right.await?; |
|
|
Ok(Completion::new()) |
|
|
} else { |
|
|
self.0 |
|
|
.iter() |
|
|
.map(|&c| async move { |
|
|
|
|
|
|
|
|
wrap(*c).await?; |
|
|
Ok(()) |
|
|
}) |
|
|
.try_join() |
|
|
.await?; |
|
|
Ok(Completion::new()) |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn wrap(completion: Vc<Completion>) -> Result<Vc<Completion>> { |
|
|
completion.await?; |
|
|
Ok(Completion::new()) |
|
|
} |
|
|
|