Last active
January 2, 2019 07:30
-
-
Save bearprada/41ca00b3ee618bfefaaf15fbefc6f0f5 to your computer and use it in GitHub Desktop.
TakeUntil and TakeLast Behavior
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
fun unsubsribeFirst() { | |
val input = PublishSubject.create<Int>() | |
val lifetime = CompletableSubject.create() | |
input.ignoreElements().subscribe(lifetime) | |
input.takeLast(2) | |
.subscribeUntil(lifetime) { println("$it") } | |
println("start") | |
input.onNext(1) | |
input.onNext(2) | |
input.onNext(3) | |
input.onComplete() | |
println("end") | |
} | |
fun unsubscribeLater() { | |
val input = PublishSubject.create<Int>() | |
val lifetime = CompletableSubject.create() | |
input.takeLast(2) | |
.subscribeUntil(lifetime) { println("$it") } | |
input.ignoreElements().subscribe(lifetime) | |
println("start") | |
input.onNext(1) | |
input.onNext(2) | |
input.onNext(3) | |
input.onComplete() | |
println("end") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
log from
unscubscribeFirst()
logs from
unsubscribeLater()