--

Just a heads up that using channels for events that way can cause the loss of events if you're not super careful. (I used to use this pattern too. I even wrote an article about it only to find out a few months afterwards that it's not safe.)

If you're using Dispatchers.Main.immediate throughout the entire event chain then maybe it will work, but that's brittle. Execellent article otherwise!

See for reference https://github.com/Kotlin/kotlinx.coroutines/issues/2886 . And a Kotlin playground that demonstrates the issue: https://pl.kotl.in/efsPK1wi8

--

--

Michael Ferguson
Michael Ferguson

Written by Michael Ferguson

Android software developer. Views and opinions expressed are my own and not that of my employer.

Responses (1)