forked from ROMEO/nexosim
Add AutoActionKey
This commit is contained in:
parent
cb7caa10e9
commit
8b015b2eba
@ -132,7 +132,7 @@ pub(crate) use scheduler::{
|
|||||||
schedule_periodic_event_at_unchecked, schedule_periodic_keyed_event_at_unchecked,
|
schedule_periodic_event_at_unchecked, schedule_periodic_keyed_event_at_unchecked,
|
||||||
KeyedOnceAction, KeyedPeriodicAction, OnceAction, PeriodicAction, SchedulerQueue,
|
KeyedOnceAction, KeyedPeriodicAction, OnceAction, PeriodicAction, SchedulerQueue,
|
||||||
};
|
};
|
||||||
pub use scheduler::{Action, ActionKey, Deadline, SchedulingError};
|
pub use scheduler::{Action, ActionKey, AutoActionKey, Deadline, SchedulingError};
|
||||||
pub use sim_init::SimInit;
|
pub use sim_init::SimInit;
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
@ -54,6 +54,22 @@ impl Deadline for MonotonicTime {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Managed handle to a scheduled action.
|
||||||
|
///
|
||||||
|
/// An `AutoActionKey` is a managed handle to a scheduled action that cancels
|
||||||
|
/// action on drop.
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[must_use = "managed action key shall be used"]
|
||||||
|
pub struct AutoActionKey {
|
||||||
|
is_cancelled: Arc<AtomicBool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for AutoActionKey {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.is_cancelled.store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle to a scheduled action.
|
/// Handle to a scheduled action.
|
||||||
///
|
///
|
||||||
/// An `ActionKey` can be used to cancel a scheduled action.
|
/// An `ActionKey` can be used to cancel a scheduled action.
|
||||||
@ -80,6 +96,13 @@ impl ActionKey {
|
|||||||
pub fn cancel(self) {
|
pub fn cancel(self) {
|
||||||
self.is_cancelled.store(true, Ordering::Relaxed);
|
self.is_cancelled.store(true, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts action key to a managed key.
|
||||||
|
pub fn into_auto(self) -> AutoActionKey {
|
||||||
|
AutoActionKey {
|
||||||
|
is_cancelled: self.is_cancelled,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for ActionKey {
|
impl PartialEq for ActionKey {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user