Last active
May 31, 2021 20:20
-
-
Save ericntd/b2b641ebb990148bbf4d21cc56e8b945 to your computer and use it in GitHub Desktop.
Simulate Room RxJava read timeout in happy path
This file contains hidden or 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
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