Created
December 29, 2017 09:25
-
-
Save neworld/dd0548ea09f123077980c8db06d9b641 to your computer and use it in GitHub Desktop.
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
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