Trait TimerTaskQueue
pub trait TimerTaskQueue {
type Item;
type Instant;
type Key: Send + Sync + 'static;
type DueBatch: IntoIterator<Item = Self::Item>;
type Handle: TimerQueueHandle<Item = Self::Item, Instant = Self::Instant, Key = Self::Key>;
Show 13 methods
// Required methods
fn handle(&self) -> Self::Handle;
fn try_push_local(
&mut self,
deadline: Self::Instant,
item: Self::Item,
) -> RawResult<Self::Key, TimerSubmitError<Self::Item>>;
fn request_cancel_local(
&mut self,
key: &Self::Key,
) -> RawResult<(), TimerCancelRequestError>;
fn advance(
&mut self,
now: &Self::Instant,
) -> RawResult<TimerAdvanceProgress, TimerQueueError>;
fn try_take_due_one(
&mut self,
) -> RawResult<TimerTake<Self::Item>, TimerQueueError>;
fn try_take_due_all(
&mut self,
) -> RawResult<TimerTake<Self::DueBatch>, TimerQueueError>;
fn process_cleanup(&mut self) -> Result<QueueCleanupProgress>;
fn next_check_at(
&self,
now: &Self::Instant,
) -> RawResult<Option<Self::Instant>, TimerQueueError>;
fn status(&self) -> TimerQueueStatus;
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn clear(&mut self) -> Result<QueueCleanupProgress>;
fn close(&mut self) -> Result<QueueCleanupProgress>;
}Expand description
原定时来源的本地拥有者;排他方法不自动证明调用线程(thread)符合所属域要求。
Item、Instant不施加全局可跨线程转移(Send)或共享(Sync)约束。
共享入口提交时才要求相应值Send + ’static;本地入口可接收非Send原异步计算(Future)。
所属线程(owner thread)的轮询(poll)/析构(drop)责任不能通过共享句柄(shared handle)绕过。
所有操作同步完成本次有限工作,不等待未来内容或其它线程(thread)完成发布,不无限自旋。 允许实现已说明的短时同步成本;有限工作不保证固定墙钟耗时。各方法的具体复杂度、 分配及工作额度由实现说明,不强制每次调用者传预算,也不要求默认堆分配(heap allocation)。
Required Associated Types§
type Item
type Item
原登记内容,可为可执行句柄(Runnable)或计时登记;不要求额外封装新任务(Task)。
type Instant
type Instant
同一时钟实例、起点和单位下的绝对时刻;构造和实现负责其关联及比较。 不要求复制或全序比较,不指定为整数或标准库(standard library)时刻。
type Key: Send + Sync + 'static
type Key: Send + Sync + 'static
原登记的不透明键(opaque key),不强制可复制(Copy)或可克隆(Clone)。 正常释放不取消;内部移动保持身份,过期或错误来源不能命中另一登记。
type DueBatch: IntoIterator<Item = Self::Item>
type DueBatch: IntoIterator<Item = Self::Item>
独立拥有的有限到期序列;迭代不回访来源,不吸收新内容,不携带队列(queue)保护。
type Handle: TimerQueueHandle<Item = Self::Item, Instant = Self::Instant, Key = Self::Key>
type Handle: TimerQueueHandle<Item = Self::Item, Instant = Self::Instant, Key = Self::Key>
同一原来源的受限共享入口;类型(type)匹配不单独证明实例匹配。
Required Methods§
fn handle(&self) -> Self::Handle
fn handle(&self) -> Self::Handle
取得同一原来源的共享句柄(shared handle),不新建队列(queue)或重置状态(state)。 不强制使用Arc或进行分配;取得/释放句柄(handle)本身不取消登记。
fn try_push_local(
&mut self,
deadline: Self::Instant,
item: Self::Item,
) -> RawResult<Self::Key, TimerSubmitError<Self::Item>>
fn try_push_local( &mut self, deadline: Self::Instant, item: Self::Item, ) -> RawResult<Self::Key, TimerSubmitError<Self::Item>>
本地尝试接收item及同源绝对deadline,成功立即返回稳定的原登记键(key)。
明确拒绝须返还原item,不能执行后再拒绝;接收后才发现的问题由来源继续负责。
截止时间(deadline)不从其它时钟重新推导;具体可表示范围由实现说明,非法值报
InvalidTime。无全局Send约束;可变访问不允许在错误线程(thread)触及本地原值。
fn request_cancel_local(
&mut self,
key: &Self::Key,
) -> RawResult<(), TimerCancelRequestError>
fn request_cancel_local( &mut self, key: &Self::Key, ) -> RawResult<(), TimerCancelRequestError>
本地同步记录或合并key的取消请求(cancellation request),不消费键(key)。
Ok(())只证明请求被记录/合并,不证明登记存在、请求已落实、任务(Task)已取消
或原异步计算(Future)已析构(drop)。已知无法发布才返回错误;重复请求不重复
交付原值。错来源和过期身份不能影响另一登记,不等待取消完成。
fn advance(
&mut self,
now: &Self::Instant,
) -> RawResult<TimerAdvanceProgress, TimerQueueError>
fn advance( &mut self, now: &Self::Instant, ) -> RawResult<TimerAdvanceProgress, TimerQueueError>
以外部给定的绝对now有限推进内部计时;不交出内容,也不自行获取时间。
now与提交时刻来自同一时钟;相同时间重复合法,不重复交付。
早于已接受推进时间时,在产生推进效果之前返回InvalidTime,不回退或夹到当前值。
ReachedTarget与MoreWork区分本次目标是否追完;MoreWork不携带原值。
不能因持续追赶时间而阻挡取消(cancellation)清理或关闭。
fn try_take_due_one(
&mut self,
) -> RawResult<TimerTake<Self::Item>, TimerQueueError>
fn try_take_due_one( &mut self, ) -> RawResult<TimerTake<Self::Item>, TimerQueueError>
最多交出一份可交付到期原值,不等待其它到期项发现或后来提交。
不读取另一时钟,使用已有显式推进依据。
Ready取得原值及后续责任;不保证本次已经发现全部到期内容。
fn try_take_due_all(
&mut self,
) -> RawResult<TimerTake<Self::DueBatch>, TimerQueueError>
fn try_take_due_all( &mut self, ) -> RawResult<TimerTake<Self::DueBatch>, TimerQueueError>
完整交出本次固定范围内当前全部到期原值,不接受每次数量上限。
开始时固定参考时间与已接收内容范围,后来到达内容留到下次,不无限扩批。
尚不能证明完整时返回WouldBlock并保留原值,不以已发现前缀冒充全部;
已知无内容才返回Empty。Ready序列非空,顺序由实现说明且调用者保持。
序列拥有原值,返回前结束相关借用和同步保护,后续迭代不回访来源。
fn process_cleanup(&mut self) -> Result<QueueCleanupProgress>
fn process_cleanup(&mut self) -> Result<QueueCleanupProgress>
在合法所属线程(owner thread)内部处理有限待清理内容,不要求到期、空闲或追完时间。
不向调用者交出原值,不启动新的全量清理范围或关闭;原已确定缘由保持。
来源负责原值、计数、键(key)关联及必要等待通知,不能遗留计时等待。
原Future若须经所属线程(owner thread)另行清理,只能经原任务(Task)机制合法移交,
不伪造析构(drop)成功。MoreWork或Err时来源继续保有未完成责任。
fn next_check_at(
&self,
now: &Self::Instant,
) -> RawResult<Option<Self::Instant>, TimerQueueError>
fn next_check_at( &self, now: &Self::Instant, ) -> RawResult<Option<Self::Instant>, TimerQueueError>
只读取得最迟必须再次检查本来源的绝对时刻,可保守提前。
now必须与其它时间输入同源;已知立即有工作返回本次now对应时刻。
只有确认没有再次检查的约束时才返回None,未知情况不能伪装成None。
不推进计时、不要求全扫描或精确最小期限。调用者用结果限制休眠(sleep),
仍须保留发布通知及休眠前检查,不以本次样本承诺未来无工作。
fn status(&self) -> TimerQueueStatus
fn status(&self) -> TimerQueueStatus
查询来源状态快照(snapshot),不推进计时或业务;不与另一次数量读取组成全局瞬间。
fn len(&self) -> usize
fn len(&self) -> usize
查询已接收、尚未交出/实际清理的全部登记数。 包含共享中转、原生存储、到期及待清理缓冲;内部移动或取消标记不减数。 实际交付/清理恰减一次,不包含已经交给执行器(executor)的在途任务(in-flight task)。
fn clear(&mut self) -> Result<QueueCleanupProgress>
fn clear(&mut self) -> Result<QueueCleanupProgress>
有限清理本次固定范围,不关闭接收,不要求到期,不业务轮询(poll)。
未完成时再次调用继续原范围;后来提交留给下一轮范围,不能无限扩展本次工作。
在合法上下文由来源内部处理,不交还待清理原值;保留已确定缘由并结束相应等待责任。
MoreWork或Err时剩余原值及责任仍由来源保管,已有合法变化不回滚。
fn close(&mut self) -> Result<QueueCleanupProgress>
fn close(&mut self) -> Result<QueueCleanupProgress>
先停收,再复用清理;重复调用幂等(idempotent),错误不重新开放。
包含未完成的旧清理及停收前所有已接收内容,包括有保留责任的在途发布。
不强制先取回全部未到期项,不等其它线程(thread)或所有句柄(handle)释放。
有限工作未结束报MoreWork;只有本来源全部责任已完成/合法移交才报Complete。
原值析构(drop)、异常展开(unwinding)与通知失败依既有任务(Task)责任处理,
本接口(API)不新增恐慌(panic)捕获层,也不报告任务(Task)层已全部退出。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".