Skip to content

Instantly share code, notes, and snippets.

@cypressious
Created May 25, 2016 20:34
Show Gist options
  • Save cypressious/d0355e75f462b4eff764f92f48c12d90 to your computer and use it in GitHub Desktop.
Save cypressious/d0355e75f462b4eff764f92f48c12d90 to your computer and use it in GitHub Desktop.
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