Skip to main content

pi_async_executor/timer/
protocol.rs

1//! 执行器(executor)连接既有计时来源的窄协议。
2use pi_async_runtime_core::{
3    definitions::RuntimeId,
4    time::{TimerAccess, TimerEntry},
5};
6use pi_async_task_queue::{
7    management::QueueCleanupProgress,
8    timer::{TimerSubmitError, TimerTaskQueue},
9};
10use pi_clock_manual::global::GlobalManualInstant;
11
12/// 当前运行时(runtime)本地设施通过静态方法交付同一原值;实现不持有跨线程本地指针。
13///
14/// 具体实现先经当前本地权限核RuntimeId、原线程及存续,再短暂借用本地来源;
15/// 失败返还原值。此接口不负责公共选择,不创建线程,不把借用保留到用户异步等待。
16pub trait LocalTimerSubmit<Item>: 'static {
17    fn try_push_local(
18        runtime: RuntimeId,
19        deadline: GlobalManualInstant,
20        item: Item,
21    ) -> pi_result::RawResult<pi_async_task_queue::CancelTimerKey, TimerSubmitError<Item>>;
22}
23
24/// 既有定时队列(timer queue)与核心计时访问的组合;静态分发,不暴露给普通业务使用者。
25///
26/// 原TimerTaskQueue仍管理时间、取出和清理;本接口仅增加同源核心访问和有限取消重试。
27/// Item精确关联同一Access的登记类型,不把任意队列载荷当核心计时原值。
28pub trait ExecutorTimer:
29    TimerTaskQueue<
30    Item = TimerEntry<
31        <Self as TimerTaskQueue>::Key,
32        <<Self as ExecutorTimer>::Access as TimerAccess>::Registration,
33    >,
34>
35{
36    type Access: TimerAccess<
37        Instant = <Self as TimerTaskQueue>::Instant,
38        Key = <Self as TimerTaskQueue>::Key,
39    >;
40    fn timer_access(&self) -> Self::Access;
41    /// 在普通定时推进前有限处理预备取消节点;不分配每次重试,不等待键或其它发布者。
42    fn process_cancel_retries(&mut self) -> pi_result::Result<QueueCleanupProgress>;
43}