summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2022-04-16 10:00:04 -0300
committerSoniEx2 <endermoneymod@gmail.com>2022-04-16 10:00:04 -0300
commit11267ce31034f800e033ef98eff8b5979e6e8cd1 (patch)
tree2736cf3a1af6dc56eb51009da55e922a61b0e4be /src
parent2b65b6bda3a3467a088aba7ed31e5990971bfe31 (diff)
Add a method to inspect hook liveness
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f539a58..bff39e2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -395,6 +395,28 @@ impl<F> InvalidContextError<F> {
     }
 }
 
+impl<'ph, 'f> HookHandle<'ph, 'f> where 'ph: 'f {
+    /// If this is a timer hook, returns whether the hook has expired.
+    ///
+    /// Otherwise, returns false.
+    ///
+    /// # Examples
+    ///
+    /// ```no_run
+    /// use hexchat_unsafe_plugin::{HookHandle};
+    ///
+    /// /// Remove timers that have expired.
+    /// fn clean_up_timers(timers: &mut Vec<HookHandle<'_, '_>>) {
+    ///     timers.retain(|timer| {
+    ///         !timer.expired()
+    ///     });
+    /// }
+    /// ```
+    pub fn expired(&self) -> bool {
+        self.freed.get()
+    }
+}
+
 impl<'ph, 'f> Drop for HookHandle<'ph, 'f> where 'ph: 'f {
     fn drop(&mut self) {
         if self.freed.get() {