Files
LLeMbas-TTY/mux/src/activity.rs
T
Wez Furlong 1cbaf55640 change mux empty poll to mux empty event
As part of reducing the amount of regularly scheduled stuff wezterm
does in the background, this commit restructures how an empty mux
is detected; now when the mux prunes dead windows it will emit
an Empty event.

The Activity type will now schedule a prune when it is dropped,
which will clean up and trigger the Empty event.

refs: https://github.com/wez/wezterm/issues/770
2021-05-08 10:25:49 -07:00

37 lines
979 B
Rust

//! Keeps track of the number of user-initiated activities
use crate::Mux;
use std::sync::atomic::{AtomicUsize, Ordering};
static COUNT: AtomicUsize = AtomicUsize::new(0);
/// Create and hold on to an Activity while you are processing
/// the direct result of a user initiated action, such as preparing
/// to open a window.
/// Once you have opened the window, drop the activity.
/// The activity is used to keep the frontend alive even if there
/// may be no windows present in the mux.
pub struct Activity {}
impl Activity {
pub fn new() -> Self {
COUNT.fetch_add(1, Ordering::SeqCst);
Self {}
}
pub fn count() -> usize {
COUNT.load(Ordering::SeqCst)
}
}
impl Drop for Activity {
fn drop(&mut self) {
COUNT.fetch_sub(1, Ordering::SeqCst);
promise::spawn::spawn_into_main_thread(async move {
let mux = Mux::get().unwrap();
mux.prune_dead_windows();
})
.detach();
}
}