Created
March 4, 2021 08:23
-
-
Save robertlevonyan/4cb099dd28391a2658356fafb537fdbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ObjectBoxDao() : DbRepository { | |
// create a Box instance for Movie type | |
private val moviesBox: Box<Movie> = ObjectBox.boxStore.boxFor(ObMovie::class.java) | |
override suspend fun save(movies: List<Movie>) { | |
moviesBox.put(movies) | |
} | |
override fun getMovies(): Flow<List<Movie>> = callbackFlow { // wrap response in a callback flow | |
val subscription = moviesBox.query().build().subscribe() | |
.observer { data -> offer(data.map { it.toMovie() }) } | |
awaitClose { subscription.cancel() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment