All Projects → mitchtabian → Flows-and-Channels

mitchtabian / Flows-and-Channels

Licence: other
Playground for Kotlin Flows and Channels

Programming Languages

kotlin
9241 projects

Flows-and-Channels

Playground for Kotlin Flows and Channels


I made this example as a playground to get familiar with Kotlin Channels and Flows.

Additionally, I was hoping to solve an issue with the way I make requests using MVI architecture. I use a switchmap to detect new StateEvents which then execute the corresponding request in repository layer.

example

val dataState: LiveData<DataState<ViewState>> = Transformations
    .switchMap(_stateEvent){ stateEvent ->
        stateEvent?.let {
            handleStateEvent(it) // emit from repo
    }
}

The problem with doing it this way is only one request can be executing at any given time. So any concurrency is pretty much out of the question without some serious refactoring. Everything else about this works great so I didn't want to trash it completely.

Turns out Flows are a great way to solve this issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].