Skip to main content

gpui_platform/
executor.rs

1//! Executor and dispatcher vocabulary shared by `gpui` and its platform backends.
2
3use async_task::Runnable;
4use gpui_util::Deferred;
5use scheduler::RunnableMeta;
6
7/// Keeps an operating system activity, such as an idle sleep inhibitor, alive until dropped.
8pub struct ActivityGuard {
9    _release: Deferred<Box<dyn FnOnce() + Send>>,
10}
11
12impl ActivityGuard {
13    /// Runs `release` when the guard is dropped.
14    pub fn new(release: impl FnOnce() + Send + 'static) -> Self {
15        Self {
16            _release: gpui_util::defer(Box::new(release)),
17        }
18    }
19
20    /// A guard for platforms without a corresponding activity.
21    pub fn noop() -> Self {
22        Self::new(|| {})
23    }
24}
25
26/// Type alias for runnables with metadata.
27/// Previously an enum with a single variant, now simplified to a direct type alias.
28#[doc(hidden)]
29pub type RunnableVariant = Runnable<RunnableMeta>;
30
31#[doc(hidden)]
32pub type TimerResolutionGuard = Deferred<Box<dyn FnOnce() + Send>>;