Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ExitGuard API #8717

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions crates/turbopack-trace-utils/src/exit.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
use std::{
future::Future,
pin::Pin,
sync::{Arc, Mutex, OnceLock},
sync::{Arc, OnceLock},
};

use anyhow::Result;
use tokio::{select, sync::mpsc, task::JoinSet};

/// A guard for the exit handler. When dropped, the exit guard will be dropped.
/// It might also be dropped on Ctrl-C.
pub struct ExitGuard<T>(Arc<Mutex<Option<T>>>);

impl<T> Drop for ExitGuard<T> {
fn drop(&mut self) {
drop(self.0.lock().unwrap().take())
}
}

impl<T: Send + 'static> ExitGuard<T> {
/// Drop a guard when Ctrl-C is pressed or the [ExitGuard] is dropped.
pub fn new(guard: T) -> Result<Self> {
let guard = Arc::new(Mutex::new(Some(guard)));
{
let guard = guard.clone();
tokio::spawn(async move {
tokio::signal::ctrl_c().await.unwrap();
drop(guard.lock().unwrap().take());
std::process::exit(0);
});
}
Ok(ExitGuard(guard))
}
}

type BoxExitFuture = Pin<Box<dyn Future<Output = ()> + Send + 'static>>;

/// The singular global ExitHandler. This is primarily used to ensure
Expand Down
Loading