Skip to main content

ferroui_base/platform/
i_platform_threading_interface.rs

1use std::rc::Rc;
2use std::sync::Arc;
3use std::time::Duration;
4
5use crate::reactive::IDisposable;
6use crate::threading::{DispatcherImplEvent, DispatcherPriority};
7
8pub use crate::threading::IPlatformThreadingSignal;
9
10/// A running platform timer; disposing it stops the timer. See
11/// [`IPlatformThreadingInterface::start_timer`].
12pub type PlatformTimerHandle = Rc<dyn IDisposable>;
13
14/// Provides platform-specific services relating to threading.
15///
16/// This is the legacy contract; platforms are expected to implement
17/// [`IDispatcherImpl`](crate::threading::IDispatcherImpl) instead. Like that
18/// contract it belongs to its loop thread, except for the handle returned by
19/// [`signal_handle`](Self::signal_handle).
20pub trait IPlatformThreadingInterface {
21    /// Starts a timer.
22    ///
23    /// `tick` is called on the loop thread every `interval` until the
24    /// returned value is disposed.
25    fn start_timer(&self, priority: DispatcherPriority, interval: Duration, tick: Rc<dyn Fn()>) -> PlatformTimerHandle;
26
27    fn signal(&self, priority: DispatcherPriority);
28
29    /// The thread-safe handle that does what [`signal`](Self::signal) does.
30    fn signal_handle(&self) -> Arc<dyn IPlatformThreadingSignal>;
31
32    fn current_thread_is_loop_thread(&self) -> bool;
33
34    /// Raised on the loop thread in response to a signal.
35    fn signaled(&self) -> &DispatcherImplEvent<Option<DispatcherPriority>>;
36}