Struct ConfiguredLocalRuntime
pub struct ConfiguredLocalRuntime<I, T>{ /* private fields */ }Expand description
按实际队列配置使用的单线程本地运行时(single-threaded local runtime)。
运行时(runtime)自身的提交与推进限于所属线程(owner thread)。定时任务队列(timer task queue)存在时可用
RuntimeTime、RuntimeWait 和 TimedTaskDispatch。空闲任务队列(idle task queue)
存在时可用 IdleDispatch。本地关联方法使用构造返回的实际类型。
Implementations§
§impl ConfiguredLocalRuntime<NoIdleQueue, NoTimerQueue<GlobalManualInstant>>
impl ConfiguredLocalRuntime<NoIdleQueue, NoTimerQueue<GlobalManualInstant>>
pub fn with_options(options: ExecutorOptions) -> Result<Self>
pub fn with_options(options: ExecutorOptions) -> Result<Self>
选择推进额度及原生线程的休眠期限。普通派发与内部任务固定共用同一队列。
pub fn with_queues<I, F, T>(
options: ExecutorOptions,
queues: LocalRuntimeQueues<I, F>,
) -> Result<ConfiguredLocalRuntime<I, T>>where
I: IdleBinding,
T: TimerBinding<ClockInstant = GlobalManualInstant>,
F: RuntimeTimerFactory<ManualClock, T, LocalTaskQueue>,
pub fn with_queues<I, F, T>(
options: ExecutorOptions,
queues: LocalRuntimeQueues<I, F>,
) -> Result<ConfiguredLocalRuntime<I, T>>where
I: IdleBinding,
T: TimerBinding<ClockInstant = GlobalManualInstant>,
F: RuntimeTimerFactory<ManualClock, T, LocalTaskQueue>,
在所属线程(owner thread)配置定时任务队列(timer task queue)和空闲任务队列(idle task queue)。
配置的管理者按值移交。选择定时时先检查全局时钟(global clock),通过构造前置检查后
才调用定时构造回调(callback)。
已从空闲任务队列取得的共享句柄(shared handle)沿原来源的提交和关闭(close)约定使用。
在浏览器(browser)启用默认定时时,由应用先启用 pi-clock-manual/browser 并安装时钟。
§Errors
启用定时但时钟未安装时返回 InvalidState。执行器选项或来源构造失败时返回原报告。
已移交的队列和未调用的回调在所属线程(owner thread)释放。
仅选配空闲任务队列时,计时方法仍会被编译器拒绝。
ⓘ
use pi_async_runtime::{ExecutorOptions, LocalRuntime, LocalRuntimeQueues, RuntimeTime};
use pi_async_task_queue::MpscIdleTaskQueue;
use std::time::Duration;
let idle = MpscIdleTaskQueue::new(Default::default()).unwrap();
let queues = LocalRuntimeQueues::default().with_idle(idle);
let runtime = LocalRuntime::with_queues(ExecutorOptions::default(), queues).unwrap();
let _ = runtime.sleep(Duration::from_millis(1));§impl<I, T> ConfiguredLocalRuntime<I, T>
impl<I, T> ConfiguredLocalRuntime<I, T>
Trait Implementations§
§impl<I, T> IdleDispatch for ConfiguredLocalRuntime<I, T>
impl<I, T> IdleDispatch for ConfiguredLocalRuntime<I, T>
§fn submit_idle(&self, task: UnsubmittedTask) -> RawResult<(), SubmitError>
fn submit_idle(&self, task: UnsubmittedTask) -> RawResult<(), SubmitError>
向同一服务的空闲来源提交普通Send任务(Task);不检查空闲、不保证未来接纳。
§fn idle_local_with_config<F, M>(
future: F,
config: TaskConfig<M>,
) -> RawResult<TaskHandle<F::Output, M>, SpawnError<F, ThreadNotifier, M>>
fn idle_local_with_config<F, M>( future: F, config: TaskConfig<M>, ) -> RawResult<TaskHandle<F::Output, M>, SpawnError<F, ThreadNotifier, M>>
从当前环境定位原服务后提交共享空闲来源;Future与输出要求Send,不要求Sync,不预先绑定执行线程。
Source§fn idle_with_config<F, M>(
&self,
future: F,
config: TaskConfig<M>,
) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output, M>, SpawnError<F, Self::Notifier, M>>
fn idle_with_config<F, M>( &self, future: F, config: TaskConfig<M>, ) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output, M>, SpawnError<F, Self::Notifier, M>>
创建并提交空闲时任务(idle task);成功只证明来源接受,不保证执行。
Source§fn idle<F>(
&self,
future: F,
) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output>, SpawnError<F, Self::Notifier>>
fn idle<F>( &self, future: F, ) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output>, SpawnError<F, Self::Notifier>>
默认配置的空闲提交;任务(Task)未接纳前仍可按原控制能力取消。
Source§fn idle_local<F>(
future: F,
) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output>, SpawnError<F, Self::Notifier>>
fn idle_local<F>( future: F, ) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output>, SpawnError<F, Self::Notifier>>
默认配置的当前空闲提交;输入保持Send约束,不等同spawn_local的本地非Send能力。
§impl<I, T> LocalTaskDispatch for ConfiguredLocalRuntime<I, T>
impl<I, T> LocalTaskDispatch for ConfiguredLocalRuntime<I, T>
§fn create_local_with_config<F, M>(
future: F,
config: TaskConfig<M>,
) -> RawResult<(UnsubmittedTask, LocalTaskHandle<F::Output, M>), CreateError<F, M>>
fn create_local_with_config<F, M>( future: F, config: TaskConfig<M>, ) -> RawResult<(UnsubmittedTask, LocalTaskHandle<F::Output, M>), CreateError<F, M>>
通过当前有效本地权限创建;原Future与输出保持原线程清理,不要求Send/Sync/Unpin。失败返还原输入。
§fn submit_local(task: UnsubmittedTask) -> RawResult<(), SubmitError>
fn submit_local(task: UnsubmittedTask) -> RawResult<(), SubmitError>
仅在原所属线程(owner thread)的有效本地范围首次提交;错误返还同一待提交值。
Source§fn create_local<F>(
future: F,
) -> Result<(UnsubmittedTask, TaskHandle<Self::Notifier, <F as Future>::Output, (), LocalOutput>), CreateError<F, ()>>
fn create_local<F>( future: F, ) -> Result<(UnsubmittedTask, TaskHandle<Self::Notifier, <F as Future>::Output, (), LocalOutput>), CreateError<F, ()>>
使用默认配置进行本地创建;无合法当前环境时明确失败,不猜测目标。
Source§fn spawn_local_with_config<F, M>(
future: F,
config: TaskConfig<M>,
) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output, M, LocalOutput>, SpawnError<F, Self::Notifier, M, LocalOutput>>
fn spawn_local_with_config<F, M>( future: F, config: TaskConfig<M>, ) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output, M, LocalOutput>, SpawnError<F, Self::Notifier, M, LocalOutput>>
组合本地创建与本地提交;不把结果变为可跨线程,不将拒绝当成取消。
Source§fn spawn_local<F>(
future: F,
) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output, (), LocalOutput>, SpawnError<F, Self::Notifier, (), LocalOutput>>
fn spawn_local<F>( future: F, ) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output, (), LocalOutput>, SpawnError<F, Self::Notifier, (), LocalOutput>>
默认配置的本地快速派发(local dispatch);不创建新线程,不内联轮询(poll)。
§impl<I, T> RuntimeBlockOn for ConfiguredLocalRuntime<I, T>
Available on non-target_family=wasm only.
impl<I, T> RuntimeBlockOn for ConfiguredLocalRuntime<I, T>
Available on non-
target_family=wasm only.§impl<I, T> RuntimeControl for ConfiguredLocalRuntime<I, T>
impl<I, T> RuntimeControl for ConfiguredLocalRuntime<I, T>
§fn request_close(&self) -> CloseRequestStatus
fn request_close(&self) -> CloseRequestStatus
请求一旦记录不因通知异常回滚,无人推进也不拒绝合法请求。
§impl<I, T> RuntimeQuery for ConfiguredLocalRuntime<I, T>
impl<I, T> RuntimeQuery for ConfiguredLocalRuntime<I, T>
§fn status(&self) -> RuntimeStatus
fn status(&self) -> RuntimeStatus
只读采样原服务Open/Closing/Closed;不推进服务,不保证下一次提交成功。
§fn is_driving(&self) -> bool
fn is_driving(&self) -> bool
查询原服务推进权当前是否实际持有;包括停放与同步钩子(hook),根专用推进不计入。
§fn last_idle_state(&self) -> IdleState
fn last_idle_state(&self) -> IdleState
读取最近一次成功策略判断的Unknown/Idle/NotIdle,不重新调用策略。
§fn close_state(&self) -> CloseState
fn close_state(&self) -> CloseState
读取自洽的关闭进度样本;Completed不代表最后共享存储已释放。
§fn external_task_count(&self) -> usize
fn external_task_count(&self) -> usize
读取已被本外部来源接收、尚未交付或合法清理的数量;与其它项独立取样。
§fn internal_task_count(&self) -> usize
fn internal_task_count(&self) -> usize
读取原内部可执行来源的数量样本;不包括纯挂起任务(Task)。
§fn timer_registration_count(&self) -> usize
fn timer_registration_count(&self) -> usize
包括纯计时信号,不把每项都称为业务任务(Task)。
§fn idle_task_count(&self) -> usize
fn idle_task_count(&self) -> usize
读取空闲来源尚保管的原任务(Task)数量;不调用空闲策略。
§fn in_flight_task_count(&self) -> usize
fn in_flight_task_count(&self) -> usize
读取已接纳且自身退出责任未结束的任务(Task)数量;不以队列数相减推导。
§fn waiting_for_wake_count(&self) -> usize
fn waiting_for_wake_count(&self) -> usize
仅已接纳、根Pending交接完成且无唤醒/取消/退出需求者。
查询成本由具体实现公开,不承诺所有实现O(1);默认执行器(executor)实现按需O(n)扫描登记。
§fn pending_cancel_task_count(&self) -> usize
fn pending_cancel_task_count(&self) -> usize
原取消已记录但最终控制结果尚未确定;重复请求不重复计数。
查询成本由具体实现公开;默认执行器(executor)实现按需O(n)扫描,默认事件循环(event loop)不主动采集。
§impl<I, T> RuntimeTime for ConfiguredLocalRuntime<I, T>
impl<I, T> RuntimeTime for ConfiguredLocalRuntime<I, T>
type Timer = <T as ExecutorTimer>::Access
§fn timeout(&self, duration: Duration) -> Timeout<Self::Timer> ⓘ
fn timeout(&self, duration: Duration) -> Timeout<Self::Timer> ⓘ
准备惰性计时等待;正时长首次poll才取时登记,至少1ms;零时长让出一次且不可取消。
§fn timeout_on<F: Future>(
&self,
future: F,
duration: Duration,
) -> TimeoutOn<Self::Timer, F> ⓘ
fn timeout_on<F: Future>( &self, future: F, duration: Duration, ) -> TimeoutOn<Self::Timer, F> ⓘ
按业务优先组合Future与计时;不要求额外Unpin/Send/Sync/’static,完成时撤销另一等待兴趣。
§fn sleep(&self, duration: Duration) -> Sleep<Self::Timer> ⓘ
fn sleep(&self, duration: Duration) -> Sleep<Self::Timer> ⓘ
准备短时等待;正时长范围1ms至1s,不返回独立控制句柄(handle),首次poll才开始。
§fn timeout_local(
duration: Duration,
) -> RawResult<Timeout<Self::Timer>, LocalRuntimeAccessError>
fn timeout_local( duration: Duration, ) -> RawResult<Timeout<Self::Timer>, LocalRuntimeAccessError>
使用当前有效的本地运行时(runtime)准备计时等待,正时长首次登记直达其本地定时任务队列。
当前本地环境不可用时同步返回错误;计时及取消(cancellation)沿用 timeout。
§fn timeout_on_local<F: Future>(
future: F,
duration: Duration,
) -> RawResult<TimeoutOn<Self::Timer, F>, LocalRuntimeAccessError>
fn timeout_on_local<F: Future>( future: F, duration: Duration, ) -> RawResult<TimeoutOn<Self::Timer, F>, LocalRuntimeAccessError>
通过当前有效的本地运行时组合业务异步计算(Future)与超时(timeout)。
业务优先,只有挂起才登记计时;业务不增加 Send、Sync、Unpin 或 ’static 约束。
§fn sleep_local(
duration: Duration,
) -> RawResult<Sleep<Self::Timer>, LocalRuntimeAccessError>
fn sleep_local( duration: Duration, ) -> RawResult<Sleep<Self::Timer>, LocalRuntimeAccessError>
使用当前有效的本地运行时准备短时等待,时长与完成语义沿用 sleep。
§impl<I, T> RuntimeWait for ConfiguredLocalRuntime<I, T>
impl<I, T> RuntimeWait for ConfiguredLocalRuntime<I, T>
Source§fn wait_one_timeout<T>(
&self,
duration: Duration,
) -> (WaitOneTimeout<Self::Timer, T>, OneSender<T>)
fn wait_one_timeout<T>( &self, duration: Duration, ) -> (WaitOneTimeout<Self::Timer, T>, OneSender<T>)
返回一次交值等待与原单发送者;通过timeout_on组合,不新增T的Send/Sync/’static/Unpin约束。
Source§fn wait_any_timeout<T>(
&self,
duration: Duration,
) -> (WaitAnyTimeout<Self::Timer, T>, AnySender<T>)
fn wait_any_timeout<T>( &self, duration: Duration, ) -> (WaitAnyTimeout<Self::Timer, T>, AnySender<T>)
返回并发竞争一次交值的等待与可克隆发送者;保留原胜者及关闭错误语义。
Source§fn wait_all_timeout<T>(
&self,
duration: Duration,
) -> (WaitAllTimeout<Self::Timer, T>, AllSender<T>)
fn wait_all_timeout<T>( &self, duration: Duration, ) -> (WaitAllTimeout<Self::Timer, T>, AllSender<T>)
返回全部交值等待与原登记发送者;正常返回完整有序向量,超时不交部分结果。
§impl<I, T> TaskDispatch for ConfiguredLocalRuntime<I, T>
impl<I, T> TaskDispatch for ConfiguredLocalRuntime<I, T>
type Notifier = ThreadNotifier
§fn create_with_config<F, M>(
&self,
future: F,
config: TaskConfig<M>,
) -> RawResult<(UnsubmittedTask, TaskHandle<F::Output, M>), CreateError<F, M>>
fn create_with_config<F, M>( &self, future: F, config: TaskConfig<M>, ) -> RawResult<(UnsubmittedTask, TaskHandle<F::Output, M>), CreateError<F, M>>
创建原服务的可跨线程任务(Task)并保留配置;不提交、不接纳、不轮询(poll)。失败返还原Future和配置。
§fn submit(&self, task: UnsubmittedTask) -> RawResult<(), SubmitError>
fn submit(&self, task: UnsubmittedTask) -> RawResult<(), SubmitError>
向创建它的原服务提交唯一原值;明确拒绝返还原持有及原因,不取消、不改线程归属。
Source§fn create<F>(
&self,
future: F,
) -> Result<(UnsubmittedTask, TaskHandle<Self::Notifier, <F as Future>::Output>), CreateError<F, ()>>
fn create<F>( &self, future: F, ) -> Result<(UnsubmittedTask, TaskHandle<Self::Notifier, <F as Future>::Output>), CreateError<F, ()>>
使用默认配置创建;返回唯一待提交值与结果句柄(handle),不隐式派发。
Source§fn spawn_with_config<F, M>(
&self,
future: F,
config: TaskConfig<M>,
) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output, M>, SpawnError<F, Self::Notifier, M>>
fn spawn_with_config<F, M>( &self, future: F, config: TaskConfig<M>, ) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output, M>, SpawnError<F, Self::Notifier, M>>
组合一次创建与提交;错误按创建/提交阶段保留对应原值,成功不表示已经执行。
§impl<I, T> TimedTaskDispatch for ConfiguredLocalRuntime<I, T>
impl<I, T> TimedTaskDispatch for ConfiguredLocalRuntime<I, T>
§fn spawn_timing_with_config<F, M>(
&self,
future: F,
delay: Duration,
config: TaskConfig<M>,
) -> RawResult<TaskHandle<TimedTaskNotifier<ThreadNotifier, T::Access>, F::Output, M>, SpawnError<F, TimedTaskNotifier<ThreadNotifier, T::Access>, M>>
fn spawn_timing_with_config<F, M>( &self, future: F, delay: Duration, config: TaskConfig<M>, ) -> RawResult<TaskHandle<TimedTaskNotifier<ThreadNotifier, T::Access>, F::Output, M>, SpawnError<F, TimedTaskNotifier<ThreadNotifier, T::Access>, M>>
同步固定本次截止时间并提交定时来源;准备失败保原Future,明确拒绝保原任务(Task)和结果句柄(handle)。
§fn spawn_timing_local_with_config<F, M>(
future: F,
delay: Duration,
config: TaskConfig<M>,
) -> RawResult<TaskHandle<TimedTaskNotifier<ThreadNotifier, T::Access>, F::Output, M, LocalOutput>, SpawnError<F, TimedTaskNotifier<ThreadNotifier, T::Access>, M, LocalOutput>>
fn spawn_timing_local_with_config<F, M>( future: F, delay: Duration, config: TaskConfig<M>, ) -> RawResult<TaskHandle<TimedTaskNotifier<ThreadNotifier, T::Access>, F::Output, M, LocalOutput>, SpawnError<F, TimedTaskNotifier<ThreadNotifier, T::Access>, M, LocalOutput>>
当前原线程内同步定时派发(timed dispatch);原Future/输出不要求Send/Sync,准备和拒绝均保留原值。
Source§fn spawn_timing<F>(
&self,
future: F,
delay: Duration,
) -> Result<TaskHandle<TimedTaskNotifier<Self::Notifier, Self::Timer>, <F as Future>::Output>, SpawnError<F, TimedTaskNotifier<Self::Notifier, Self::Timer>>>
fn spawn_timing<F>( &self, future: F, delay: Duration, ) -> Result<TaskHandle<TimedTaskNotifier<Self::Notifier, Self::Timer>, <F as Future>::Output>, SpawnError<F, TimedTaskNotifier<Self::Notifier, Self::Timer>>>
默认配置的同步定时派发(timed dispatch);零时长仍入定时来源,不直接执行。
Source§fn spawn_timing_local<F>(
future: F,
delay: Duration,
) -> Result<TaskHandle<TimedTaskNotifier<Self::Notifier, Self::Timer>, <F as Future>::Output, (), LocalOutput>, SpawnError<F, TimedTaskNotifier<Self::Notifier, Self::Timer>, (), LocalOutput>>
fn spawn_timing_local<F>( future: F, delay: Duration, ) -> Result<TaskHandle<TimedTaskNotifier<Self::Notifier, Self::Timer>, <F as Future>::Output, (), LocalOutput>, SpawnError<F, TimedTaskNotifier<Self::Notifier, Self::Timer>, (), LocalOutput>>
默认配置的本地定时派发(timed dispatch);不跳过原所属域或定时来源。
Auto Trait Implementations§
impl<I, T> !Freeze for ConfiguredLocalRuntime<I, T>
impl<I, T> !RefUnwindSafe for ConfiguredLocalRuntime<I, T>
impl<I, T> !Send for ConfiguredLocalRuntime<I, T>
impl<I, T> !Sync for ConfiguredLocalRuntime<I, T>
impl<I, T> !UnwindSafe for ConfiguredLocalRuntime<I, T>
impl<I, T> Forget for ConfiguredLocalRuntime<I, T>
impl<I, T> Move for ConfiguredLocalRuntime<I, T>
impl<I, T> Unpin for ConfiguredLocalRuntime<I, T>where
ConfiguredRuntime<ConcurrentMode, ManualClock, DefaultIdlePolicy, NoHooks, LocalSource, I, T, LocalTaskQueue>: Unpin,
Rc<ExecutorLocal<T, LocalTaskQueue>>: Unpin,
impl<I, T> UnsafeUnpin for ConfiguredLocalRuntime<I, T>where
ConfiguredRuntime<ConcurrentMode, ManualClock, DefaultIdlePolicy, NoHooks, LocalSource, I, T, LocalTaskQueue>: UnsafeUnpin,
Rc<ExecutorLocal<T, LocalTaskQueue>>: UnsafeUnpin,
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