Skip to content

Instantly share code, notes, and snippets.

@cmelchior
Created July 16, 2021 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmelchior/cc4385ba54864f8cbb54eb73f14d8ec6 to your computer and use it in GitHub Desktop.
Save cmelchior/cc4385ba54864f8cbb54eb73f14d8ec6 to your computer and use it in GitHub Desktop.
Realm Kotlin 0.40 Release Blog Post - Threadsafe Observers
val jane = getJane()
CoroutineScope(Dispatchers.Main).launch {
// Run mapping/transform logic in the background
val flow: Flow<String> = jane.observe()
.filter { it.name.startsWith("Jane") }
.flowOn(Dispatchers.Unconfined)
// Before collecting on the UI thread
flow.collect {
println(it.name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment