pub struct LaunchedEffectScope { /* private fields */ }Expand description
The scope a LaunchedEffect receives: the effect’s coroutine scope.
The effect is cancelled when its keys change or its call site leaves the
composition. The cancellation drops the effect’s future where it waits.
No line after that .await runs. The cancellation also cancels every task
the scope launched.
Implementations§
Source§impl LaunchedEffectScope
impl LaunchedEffectScope
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Returns true until the effect is cancelled. The effect is cancelled
when its keys change or its call site leaves the composition.
Sourcepub fn runtime(&self) -> RuntimeHandle
pub fn runtime(&self) -> RuntimeHandle
Returns a handle to the runtime that runs the effect.
Sourcepub async fn with_frame_nanos<R>(&self, on_frame: impl FnOnce(u64) -> R) -> R
pub async fn with_frame_nanos<R>(&self, on_frame: impl FnOnce(u64) -> R) -> R
Waits for the next frame, then calls on_frame with the frame time in
nanoseconds and returns what it returns. Compose’s withFrameNanos.
Await it in a loop to run once per frame:
LaunchedEffect((), async move |scope| loop {
scope.with_frame_nanos(|nanos| time.set(nanos)).await;
});Sourcepub async fn with_frame_millis<R>(&self, on_frame: impl FnOnce(u64) -> R) -> R
pub async fn with_frame_millis<R>(&self, on_frame: impl FnOnce(u64) -> R) -> R
Waits for the next frame, then calls on_frame with the frame time in
milliseconds and returns what it returns. Compose’s withFrameMillis.
Sourcepub fn launch(&self, future: impl Future<Output = ()> + 'static)
pub fn launch(&self, future: impl Future<Output = ()> + 'static)
Launches future on the UI thread as a child of the effect, as
Compose’s launch inside a LaunchedEffect does: the effect’s
cancellation cancels it too.
Sourcepub fn launch_background<T, Work, Ui, Fut>(&self, work: Work, on_ui: Ui)
pub fn launch_background<T, Work, Ui, Fut>(&self, work: Work, on_ui: Ui)
Runs background work and delivers results to the UI.
On native targets, work runs on a worker thread. Its future runs to
completion there. The on_ui continuation runs on the runtime thread.
It may capture Rc and RefCell state. It does not run once the
effect is cancelled.