Skip to main content

LaunchedEffect

Function LaunchedEffect 

Source
pub fn LaunchedEffect<K, F, Fut>(keys: K, block: F)
where K: PartialEq + 'static, F: FnOnce(LaunchedEffectScope) -> Fut + 'static, Fut: Future<Output = ()> + 'static,
Expand description

Runs block as a coroutine when this call site first enters composition, as Jetpack Compose’s LaunchedEffect does. It runs block again whenever keys no longer equals the value of the last run.

ⓘ
LaunchedEffect(line, async move |_| {
    for typed in 1..=length {
        delay(LETTER).await;
        letters.set(typed);
    }
});

A change of keys cancels the running coroutine. The call site leaving the composition cancels it too. The coroutine stops where it awaits. No line after that .await runs. keys may be a tuple to depend on more than one value, as Compose’s LaunchedEffect(vararg keys) does.