Running a slow suspend function on `Flow` that's to be rendered makes UI freeze
See original GitHub issueHi!
I’m running a slow suspend
function (~4.5s) that’s running a WASM method. The whole UI completely freezes. The code is something like
val store: RootStore
val otherStore: RootStore
render {
img { src(otherStore.data) }
store.data.map { data -> callSuspendFunction(data) } handledBy otherStore.update
}
How am I supposed to use coroutines correctly? I’ve tried using withContext
and other solutions that don’t help.
Issue Analytics
- State:
- Created 2 years ago
- Comments:14
Top Results From Across the Web
Coroutines will FREEZE your UI - YouTube
The best Android courses in the world: https://codingwithmitch.com/In this video I talk about how coroutines fundamentally work.
Read more >How to run an expensive calculation with Kotlin Coroutines on ...
There is a way to use Coroutines to run the calculation on the main thread without freezing the UI! How is this possible?...
Read more >Use Kotlin coroutines with lifecycle-aware components
This approach processes the flow emissions only when the UI is visible on the screen, saving resources and potentially avoiding app crashes. For ......
Read more >Could it be that Flow.collect() blocks the UI? - Stack Overflow
Under the hood, the suspend function is doing something asynchronously, but to the coroutine that calls it, it is treated as synchronous.
Read more >How We Reduced Our React App's Load Time by 60% - InfoQ
Using React by itself will not result in a highly performant application. ... That makes it easier to visualize how the UI works....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks, that’s really insightful.
I was afraid the issue was something along the lines of what you’re saying. I’ll see if I can get some recipe figured out. Last time I looked at building a PWA I believe that you need a new JS-file per webworker. Hopefully I’ll solve that one, and of course share it here 😄
A huge thank you for helping me come further in this issue! 🙏
Looks much nicer now.
I would suggest, that you surround your handler inside with a
try...catch
in order to catch internal exception that might bubble. I am quite sure, that I had some within two or three pictures I have tried.This should help right now.
We have encountered an issue (PR #579) dealing with our exception handling thanks to your issue here. So this might also help you if that is merged. So stay tuned 😃