https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

Dico

05/27/2019, 3:43 AM
Under what circumstances would
delay
suspend forever, if I pass it a value around 500-1500 MS? I have some code that is looping with an interval which works perfectly in one environment but not in another - where it's used as a plugin in some other software. The dispatcher used is a single thread dispatcher created using
Executors.newSingleThreadDispatcher(threadFactory).asCoroutineDispatcher()
The behavior I'm seeing is that it never resumes the coroutine.
g

gildor

05/27/2019, 4:11 AM
It may be deadlock
Especially with single thread dispatcher
If some code blocks coroutine, delay also cannot be dispatched and will never return
Do you have some use case for single threaded dispatcher?
d

Dico

05/27/2019, 6:45 AM
avoiding shared mutable state
I think it's probably blocking somewhere as well
thanks for the responses
g

gildor

05/27/2019, 6:49 AM
avoiding shared mutable state
I would use actor for this
in general limiting coroutine concurrency using threads is not really good idea (often it cause unexpected behavior, when you think that suspending will not allow other coroutines to run because you are on single threaded dispatcher), better to use actor, which is 1 coroutine that process queue of events
d

Dico

05/27/2019, 2:06 PM
I'm conscious that an actor is good for this, but it's not needed. You can actually use LimitingDispatcher atm with a bit of experimental trickery by the way, which is pretty cool.
Turns out the parent Job was getting cancelled immediately due to a big oversight
😅
5 Views