Skip to content

Instantly share code, notes, and snippets.

View datikaa's full-sized avatar

datikaa

View GitHub Profile
@datikaa
datikaa / FlowExtension.kt
Last active September 28, 2024 18:05
Updatign a Kotlin MutableStateFlow with another flow lifecycle-aware
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.runningReduce
import io.realm.*
import io.realm.kotlin.toFlow
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
/**
* Returns a [Flow] with all of the results of the [RealmQuery], while drops every offer that is not
* loaded already. This makes it easy to be used with [kotlinx.coroutines.flow.first]. Be aware that
* the [Realm] object must be on a thread with a looper.
*