What are the ways to fix this problem ?
# coroutines
i
What are the ways to fix this problem ?
w
wrap the call with
withContext
using IO dispatcher
i
fromJson
read data from
bufferedSource
might block the depended thread. Maybe nonblocking parse mode will be useful. (If the json deserializer has this feature.)
p
extract the expression to non-suspend function or remove
suspend
modifier
the reason is that
fromJson
don’t care about coroutines, it’s a blocking method call that ignores coroutine cancellation
u
@wasyl @iseki why did you strike your text? Isn’t the ide telling us that we should move this call to background:
Copy code
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
  .....fromJson(…)
}
w
Yep I got confused for a while here
👍 1
u
@igor.wojda you should always choose the appropriate dispatcher as close to the ' reason’ as possible. Do not set Dispatchers.IO at the beginning of the call chain. There you can should not know which dispatcher is the right one. Set it just around the method that really does blocking stuff