tauri_store_utils/
task.rs

1use crate::sync::MutexOption;
2use std::ops::Deref;
3use tokio::task::AbortHandle;
4
5/// A dyn compatible trait intended to be used with types
6/// like [`Debounce`](crate::Debounce) and [`Throttle`](crate::Throttle).
7pub trait RemoteCallable<T> {
8  /// Call the function with the provided context.
9  fn call(&self, ctx: &T);
10  /// Abort any pending calls.
11  fn abort(&self);
12}
13
14#[derive(Default)]
15pub(crate) struct OptionalAbortHandle(MutexOption<AbortHandle>);
16
17impl OptionalAbortHandle {
18  pub(crate) fn abort(&self) {
19    if let Some(handle) = self.0.take() {
20      handle.abort();
21    }
22  }
23}
24
25impl Deref for OptionalAbortHandle {
26  type Target = MutexOption<AbortHandle>;
27
28  fn deref(&self) -> &Self::Target {
29    &self.0
30  }
31}