question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running a slow suspend function on `Flow` that's to be rendered makes UI freeze

See original GitHub issue

Hi!

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:closed
  • Created 2 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
Lundezcommented, Feb 8, 2022

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! 🙏

1reaction
chausknechtcommented, Jan 28, 2022

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found