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

pakoito

03/06/2018, 8:25 PM
java.lang.IllegalStateException: Already resumed
So, `CoroutineContext`s are not reusable
p

pakoito

03/06/2018, 8:33 PM
I don’t deny it’s a solution, but it’s clearly one that’s not prod-ready. Sad 😞
e

elizarov

03/07/2018, 4:56 AM
Can you please elaborate what it has to do with contexts? Do you have an example code?
p

pakoito

03/07/2018, 11:11 AM
yes! what I’m trying to write is some code that enforces every flatMap to happen on the CC that’s been passed, so it reuses it
the problem is that the CC isn’t reusable so I cannot start a new coroutine for every step, even if I use EmptyCoroutineContext
e

elizarov

03/07/2018, 11:57 AM
I don’t get it.
CoroutineContext
is an immutable state-less data structure. Your problem is with something else. What kind of error you are getting?
p

pakoito

03/07/2018, 12:18 PM
java.lang.IllegalStateException: Already resumed
If I give a new CoroutineContext every time it works just correctly
the same CC is being used for multiple active corutines
so it may be the stacklabels we’re copying?
e

elizarov

03/07/2018, 1:06 PM
This is exception can be only thrown by either
suspendCoroutine
or
suspendCancellableCoroutine
and has nothing to do with the context. It happens when you try to resume the same
Continuation
twice
context, by itself, has no state
p

pakoito

03/07/2018, 1:07 PM
hmmmm
that’s good info
I can come back to the code with that, thanks 😄
30 Views