Skip to content

Instantly share code, notes, and snippets.

@digitalbuddha digitalbuddha/RxPaging.kt
Last active Aug 24, 2018

Embed
What would you like to do?
class RxPaging {
var page = 1
val cache = CacheBuilder.newBuilder().build<Any, Single<List<Single<Int>>>>()
@Test
fun getPages() {
val tab1 = pagedList().blockingGet().iterator()
val tab2 = pagedList().blockingGet().iterator()
val a = tab1.next().test().assertValue(1)
val b = tab2.next().test().assertValue(1)
val c = tab1.next().test().assertValue(2)
val d = tab1.next().test().assertValue(3)
val e = tab2.next().test().assertValue(2)
}
private fun pagedList() = cache.get("", { dbPages() })!!
private fun dbPages() = Single.just(listOf(dbPage(), dbPage(), dbPage())).cache()
private fun dbPage() = Single.fromCallable { nextPage() }.cache() //replace with DAO.getItems(offset,pageSize)
private fun nextPage(): Int = page++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.