Does `onDispose` method in `DisposableEffect` run ...
# compose
m
Does
onDispose
method in
DisposableEffect
run synchronously or it is fire and forget? I have some problems when I use
runBlocking
inside the
onDispose
callback. It seems like the composition is cancelling the scope before the
onDispose
finishes execution.
s
Is there some way you can not runBlocking on the UI thread in the first place to avoid any such potential problems?
m
Potentially I could but it would require large rework of app structure. I would like to know if it is possible that compose cancels the coroutine before onDispose finishes 🤔
z
Using runBlocking on the main thread is generally a bad idea and can introduce weird bugs. If you’re just using runBlocking though, compose shouldn’t know anything about your coroutine, let alone cancel it. This doesn’t make much sense to me without seeing your code
m
At first I thought that it is cancelling it but after some more debugging its just like You said. The main thread is freezed. So I have changed the runBlocking to a standalone coroutine and everything works fine now. Thanks for help! 🙌