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

uli

06/18/2018, 1:34 PM
Hi all, I was surprised to see, that canceling a job that is suspended in a
consumeEach
will execute code after the
consumeEach
. Is this expected behaviour? In the below example, if
job.cancel()
is called, while the job is waiting for new Items from
receiveChannel
it will print out
Done
Copy code
job = launch(coroutineContext) {
                receiveChannel.consumeEach { r ->
                    output.send(r)
                }
                println("Done")
                output.close()
            }
If relevant, I do have a self contained sample, which is an alternative implementation of @hannesstruss switchMap example. Please let me know if I should post it.
v

Vsevolod Tolstopyatov [JB]

06/18/2018, 3:54 PM
It will not.
consumeEach
re-throws exceptions. Issue is somewhere in
switchMap
implementation (I haven’t looked at it yet)
2 Views