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

Add shutdown timeout #35

Open
wants to merge 1 commit into
base: master
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
15 changes: 14 additions & 1 deletion src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use crate::Result;
const MIN_HEIGHT: usize = 1;
const WAIT_TIMEOUT: Duration = Duration::from_millis(300);
const POLLING_TIMEOUT: Duration = Duration::from_millis(10);
const SHUTDOWN_TIMEOUT: Duration = Duration::from_millis(400);

#[derive(Debug, Copy, Clone)]
pub enum TermHeight {
Expand Down Expand Up @@ -263,8 +264,20 @@ impl<UserEvent: Send + 'static> Term<UserEvent> {

termlock.pause(exiting)?;

let mut no_timeout = {
let mut wait_sum = Duration::default();
move || {
if exiting {
wait_sum += POLLING_TIMEOUT;
wait_sum <= SHUTDOWN_TIMEOUT
} else {
true
}
}
};

// wait for the components to stop
while self.components_to_stop.load(Ordering::SeqCst) > 0 {
while self.components_to_stop.load(Ordering::SeqCst) > 0 && no_timeout() {
debug!(
"pause: components: {}",
self.components_to_stop.load(Ordering::SeqCst)
Expand Down