Created
May 25, 2016 20:34
-
-
Save cypressious/d0355e75f462b4eff764f92f48c12d90 to your computer and use it in GitHub Desktop.
This file contains 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
fun <T> Observable<T>.delayUntil(value: T): Observable<T> { | |
val replaySubject = ReplaySubject.create<T>() | |
val sharedObservable = this.publish().autoConnect(2) | |
sharedObservable.subscribe(replaySubject) | |
val delayObservable = sharedObservable | |
.first { it == value } | |
.concatWith(Observable.error(IllegalArgumentException())) | |
return replaySubject.delaySubscription(delayObservable) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment