pub struct TickGuard { /* private fields */ }Available on crate feature
cronutil only.Expand description
单实例防重叠闸门; Default 即可用, Clone 共享同一把闸门。
上一轮未返回时, 下一轮直接跳过, 不排队等待
Implementations§
Source§impl TickGuard
impl TickGuard
Sourcepub fn try_acquire(&self) -> Option<TickPermit>
pub fn try_acquire(&self) -> Option<TickPermit>
尝试占用闸门; 已有轮次在执行时返回 None
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
当前是否有轮次在执行
Sourcepub fn try_run(&self, f: impl FnOnce()) -> bool
pub fn try_run(&self, f: impl FnOnce()) -> bool
尝试同步执行 f: 无其他轮次时运行并返回 true, 否则直接返回 false;
f panic 时闸门同样释放
Sourcepub async fn try_run_async<F: Future<Output = ()>>(&self, fut: F) -> bool
pub async fn try_run_async<F: Future<Output = ()>>(&self, fut: F) -> bool
异步版 TickGuard::try_run: 闸门被占用时不轮询 fut, 直接返回 false;
future 被取消或 panic 时闸门同样释放
Trait Implementations§
Auto Trait Implementations§
impl Forget for TickGuard
impl Freeze for TickGuard
impl Move for TickGuard
impl RefUnwindSafe for TickGuard
impl Send for TickGuard
impl Sync for TickGuard
impl Unpin for TickGuard
impl UnsafeUnpin for TickGuardwhere
*const ArcInner<Atomic<bool>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin,
impl UnwindSafe for TickGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more