Am I correct that `DisposableEffect` and `LaunchedEffect` are essentially the same except that they ...
v
Am I correct that
DisposableEffect
and
LaunchedEffect
are essentially the same except that they use different methods to make the same thing: `DisposableEffect`’s block is blocking and disposes stuff with
onDispose
and `LaunchedEffect`’s block is suspending and disposes stuff with
scope.cancel()
?
d
Are you actually allowed to call
scope.cancel()
? I guess you could use
awaitCancellation()
.
Kinda, you can use one to awkwardly achieve the other but they are for quite different use cases.
a
yes; mechanically very related but in conceptual usage they probably won't overlap terribly often
v
My question arises from the animation API changes in alpha12 - all
animateTo
methods are changed to be suspending now. So I wonder if I can simply change old
DisposableEffect
with
animateTo
to
LaunchedEffect
with new
animateTo
:)
a
yes 🙂 and the cleanup will be nicer since coroutine cancellation will do it for you
👍🏻 2