Skip to main content

AsyncApp

Struct AsyncApp 

Source
pub struct AsyncApp { /* private fields */ }
Expand description

前景 UI 协程持有的异步应用上下文(与 GPUI AsyncApp 对齐)。

!Send(绑定 UI 主线程),可自由跨 .await 存活并随时安全访问 PodPool、派生子任务、 发起 background_spawn 后台计算与 timer 定时器。

Implementations§

Source§

impl AsyncApp

Source

pub fn background_executor(&self) -> BackgroundExecutor

获取绑定到当前引擎调度器后端的后台异步执行器句柄(用于 .spawn(...) / .timer(Duration))。

Source

pub fn background_spawn<T, Fut>(&self, fut: Fut) -> Task<T> ⓘ
where T: Send + 'static, Fut: Future<Output = T> + Send + 'static,

在当前引擎配置的后台调度器中执行 CPU 密集型计算或阻塞 I/O,返回可 .await 的 Task<T>。

Source

pub fn timer(&self, duration: Duration) -> Timer ⓘ

创建由当前引擎调度器时钟驱动的非阻塞异步定时器(与 GPUI cx.background_executor().timer(dur) 等价简写)。

Source

pub fn scheduler_name(&self) -> &'static str

返回当前引擎配置的调度器名称。

Source

pub fn spawn<T, F, Fut>(&self, f: F) -> Task<T> ⓘ
where T: 'static, F: FnOnce(AsyncApp) -> Fut, Fut: Future<Output = T> + 'static,

在 UI 主线程前景执行器上派生子异步任务(不绑定特定视图句柄)。

Source

pub fn spawn_for<V, T, F, Fut>(&self, handle: Handle<V>, f: F) -> Task<T> ⓘ
where V: View, T: 'static, F: FnOnce(Handle<V>, AsyncApp) -> Fut, Fut: Future<Output = T> + 'static,

在 UI 主线程前景执行器上为指定视图句柄派生绑定异步任务(闭包接收 (Handle<V>, AsyncApp))。

Source

pub fn defer<F>(&self, f: F)
where F: FnOnce(&mut ActionScope<'_>) + 'static,

排入一个延迟到本轮前景调度末尾执行的 UI 主线程回调。

Source

pub fn update<V: View, R>( &mut self, handle: Handle<V>, f: impl FnOnce(&mut V, &mut ActionScope<'_>) -> R, ) -> Option<R>

在前景协程中安全更新任意 Handle<V> 视图的状态(自动校验 ABA generation、防重入、标脏并刷新信号)。 若目标视图已卸载或正在被可变借用,则安全返回 None 绝不 panic。

Source

pub fn read<V: View, R>( &self, handle: Handle<V>, f: impl FnOnce(&V) -> R, ) -> Option<R>

在前景协程中只读读取任意 Handle<V> 视图的快照数据(若目标视图已卸载则返回 None)。

Source

pub fn notify_handle<V: View>(&mut self, handle: Handle<V>)

显式标记指定视图句柄为脏。

Source

pub fn now_ms(&self) -> u32

获取当前引擎单调动画时钟(毫秒)。

Trait Implementations§

Source§

impl Clone for AsyncApp

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> FluentBuilder for T

Source§

fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self

当 condition 为 true 时执行闭包修饰自身,否则原样返回。
Source§

fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self

根据 condition 在两个修饰分支之间二选一。
Source§

fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self

当 option 为 Some(value) 时执行闭包修饰自身,否则原样返回。
Source§

fn when_none<O>( self, option: &Option<O>, then: impl FnOnce(Self) -> Self, ) -> Self

当 option 为 None 时执行闭包修饰自身,否则原样返回。
Source§

fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U

通用管道映射变换(避免与 Iterator::map / Option::map 重名)。
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.