Skip to content

Instantly share code, notes, and snippets.

@digitalbuddha
Last active August 24, 2018 01:37
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 digitalbuddha/eaeee4a34a43d840ce27b3d973af9dee to your computer and use it in GitHub Desktop.
Save digitalbuddha/eaeee4a34a43d840ce27b3d973af9dee to your computer and use it in GitHub Desktop.
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