Skip to content

Instantly share code, notes, and snippets.

@neworld
Created December 29, 2017 09:25
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 neworld/dd0548ea09f123077980c8db06d9b641 to your computer and use it in GitHub Desktop.
Save neworld/dd0548ea09f123077980c8db06d9b641 to your computer and use it in GitHub Desktop.
val checkLock = Object()
val disposeLock = Object()
val completable = Completable.create { emitter ->
synchronized(checkLock) {
checkLock.notify()
}
if (!emitter.isDisposed) {
synchronized(disposeLock) {
try {
disposeLock.wait()
} catch (e: InterruptedException) {
}
}
println("throw error")
emitter.tryOnError(RuntimeException("Race-condition"))
}
}.subscribeOn(Schedulers.io())
lateinit var disposable: Disposable
synchronized(checkLock) {
disposable = completable.subscribe({
//success
}, {
//error is handled
})
checkLock.wait()
}
synchronized(disposeLock) {
println("dispose")
disposable.dispose()
disposeLock.notify()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment