Skip to content

Instantly share code, notes, and snippets.

@ericntd
Last active May 31, 2021 20:20
Show Gist options
  • Save ericntd/b2b641ebb990148bbf4d21cc56e8b945 to your computer and use it in GitHub Desktop.
Save ericntd/b2b641ebb990148bbf4d21cc56e8b945 to your computer and use it in GitHub Desktop.
Simulate Room RxJava read timeout in happy path
import io.reactivex.BackpressureStrategy
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.TimeUnit
fun main() {
getFakeRoomReadStream()
.filter { it < 3 }
.timeout(2L, TimeUnit.SECONDS, Schedulers.io())
.observeOn(Schedulers.trampoline())
.subscribe({
println("succcess $it")
}, {
it.printStackTrace()
})
}
fun getFakeRoomReadStream(): Flowable<Int> {
return Flowable.create<Int>({
var i = 0
while (true) {
it.onNext(i)
i++
Thread.sleep(100L)
}
}, BackpressureStrategy.BUFFER)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment