Skip to content

Instantly share code, notes, and snippets.

@SergejIsbrecht
Last active January 11, 2021 12:08
Show Gist options
  • Save SergejIsbrecht/325000c247ed35a810430a02f2b568f0 to your computer and use it in GitHub Desktop.
Save SergejIsbrecht/325000c247ed35a810430a02f2b568f0 to your computer and use it in GitHub Desktop.
timeout
@Test
fun fuck1() {
val dmb = io.reactivex.schedulers.Schedulers.single()
val watchDog = io.reactivex.schedulers.Schedulers.from(Executors.newSingleThreadExecutor())
watchDog.scheduleDirect {
println("watchDog scheduleDirect " + Thread.currentThread().name)
}
dmb.scheduleDirect {
// println("block this thread " + Thread.currentThread().name)
// Thread.sleep(10_000)
}
val watchDogA = AtomicBoolean(false)
watchDog.scheduleDirect({
watchDogA.compareAndExchange(false, true)
println("watchDog scheduleDirect delayed" + Thread.currentThread().name)
}, 3, TimeUnit.SECONDS)
Thread.sleep(5_000)
assertThat(watchDogA.get()).isTrue()
}
@Test
fun fuck2() {
val dmb = io.reactivex.schedulers.Schedulers.single()
val watchDog = io.reactivex.schedulers.Schedulers.from(Executors.newSingleThreadExecutor())
watchDog.scheduleDirect {
println("watchDog scheduleDirect " + Thread.currentThread().name)
}
dmb.scheduleDirect {
println("block this thread " + Thread.currentThread().name)
Thread.sleep(10_000)
}
val watchDogA = AtomicBoolean(false)
watchDog.scheduleDirect({
watchDogA.compareAndExchange(false, true)
println("watchDog scheduleDirect delayed" + Thread.currentThread().name)
}, 3, TimeUnit.SECONDS)
Thread.sleep(5_000)
assertThat(watchDogA.get()).isTrue()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment