Skip to content

Commit

Permalink
gracefully stop turbo-tasks to allow persisting to complete
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Sep 4, 2024
1 parent 410051f commit aa5e980
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions turbopack/crates/turbo-tasks-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ impl TurboTasksApi for VcStorage {
) -> std::pin::Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>> {
unimplemented!()
}

fn stop_and_wait(&self) -> std::pin::Pin<Box<dyn Future<Output = ()> + Send + 'static>> {
Box::pin(async {})
}
}

impl VcStorage {
Expand Down
4 changes: 3 additions & 1 deletion turbopack/crates/turbo-tasks-testing/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ where
println!("Run #1 (without cache)");
let first = run_once(tt.clone(), fut()).await?;
println!("Run #2 (with memory cache, same TurboTasks instance)");
let second = run_once(tt, fut()).await?;
let second = run_once(tt.clone(), fut()).await?;
assert_eq!(first, second);
tt.stop_and_wait().await;
let tt = registration.create_turbo_tasks(&name, false);
println!("Run #3 (with persistent cache if available, new TurboTasks instance)");
let third = run_once(tt.clone(), fut()).await?;
tt.stop_and_wait().await;
assert_eq!(first, third);
Ok(())
}
10 changes: 10 additions & 0 deletions turbopack/crates/turbo-tasks/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ pub trait TurboTasksApi: TurboTasksCallApi + Sync + Send {
&self,
f: Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>;

fn stop_and_wait(&self) -> Pin<Box<dyn Future<Output = ()> + Send>>;
}

/// A wrapper around a value that is unused.
Expand Down Expand Up @@ -1335,6 +1337,13 @@ impl<B: Backend + 'static> TurboTasksApi for TurboTasks<B> {
),
))
}

fn stop_and_wait(&self) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> {
let this = self.pin();
Box::pin(async move {
this.stop_and_wait().await;
})
}
}

impl<B: Backend + 'static> TurboTasksBackendApi<B> for TurboTasks<B> {
Expand All @@ -1351,6 +1360,7 @@ impl<B: Backend + 'static> TurboTasksBackendApi<B> for TurboTasks<B> {
this.backend.run_backend_job(id, &*this).await;
})
}

#[track_caller]
fn schedule_backend_foreground_job(&self, id: BackendJobId) {
self.schedule_foreground_job(move |this| async move {
Expand Down

0 comments on commit aa5e980

Please sign in to comment.