Skip to main content

TaskRegistration

Struct TaskRegistration 

pub struct TaskRegistration { /* private fields */ }
Expand description

唯一接纳登记;由执行组织保留,释放时提出取消而不重复析构(drop)。 当前域的活跃登记另保证线程退出前完成本地原值清理;本值不可跨线程转移。

Implementations§

§

impl TaskRegistration

pub fn snapshot(&self) -> TaskSnapshot

查询本份接纳登记对应任务(Task)的基本快照(snapshot)。

可在交出可执行句柄(runnable handle)后使用,不取得新的执行或结果领取权限。 字段(field)的一致性与失效边界沿用TaskSnapshot;返回后不自动更新。 本方法同步只读,时间与额外空间均为O(1),不分配、不等待任务(Task)推进。 本登记仍只能在所属线程(thread)内使用,不能跨线程转移或共享。

§

impl TaskRegistration

pub fn is_waiting_for_wake(&self) -> bool

查询原任务(Task)是否在交接完成后等待新的任务唤醒(wake-up)。

判定与crate::control::ControlHandle::is_waiting_for_wake相同:挂起(Pending) 已稳定、没有执行访问、待处理唤醒(wake-up)、已发出执行持有、取消(cancellation)或退出才为true。 false不能证明已结束或已入队(enqueue);取样后任务(Task)可立即发生变化。

只在所属线程(thread)通过本登记同步查询。时间与额外空间均为O(1), 不分配、不等待、不改变原任务(Task)。统计时还须筛选本服务已接纳的登记; 多项查询不承诺全局同一时刻快照(snapshot)。

§

impl TaskRegistration

pub fn metadata<M: Send + Sync + 'static>(&self) -> Option<&M>

按创建时关联的类型(type),共享借用(shared borrow)本任务(Task)的附加数据(task metadata)。

M与原始类型(type)完全相符时返回Some(&M),否则返回None;不会复制或转交M。 M须满足Send、Sync及’static;只借出共享引用(shared reference),不提供任意&mut M。 M可通过其自身安全接口(API)管理内部更新,相关同步及业务成本由M的实现决定。

返回引用(reference)不超过对本登记的借用期。本登记保持有效时,原异步计算(Future) 已完成合法析构(drop)后仍可读取M;读取不要求延迟原异步计算(Future)的清理。 本方法在所属线程(thread)同步完成,时间与额外空间均为O(1),不分配、不等待, 不推进原任务(Task),也不承诺M内部多个值构成一致快照(snapshot)。

Trait Implementations§

§

impl Drop for TaskRegistration

§

fn drop(&mut self)

放弃本份接纳登记时请求退出;不撤销其它请求或重复释放原值。

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.