Skip to content

Instantly share code, notes, and snippets.

@tcw165
Created December 4, 2018 04:15
Show Gist options
  • Save tcw165/38090c0b7ac5e84a766c3aaf34af72e1 to your computer and use it in GitHub Desktop.
Save tcw165/38090c0b7ac5e84a766c3aaf34af72e1 to your computer and use it in GitHub Desktop.
val upstream = PublishSubject.create<Int>()
upstream.doOnDispose { Timber.d("Uh, the upstream gets disposed") } // This log will never print.
val tester = upstream
.flatMap { v ->
when (v) {
0 -> {
Timber.d("flatMap produces an empty")
Observable.empty<Int>()
}
else -> Observable.just(v)
}
}
.test()
upstream.onNext(0) // Will return a complete in flatMap.
upstream.onNext(1) // If the stream dies, we'll never emit this value successfully.
tester.assertValueCount(1) // Actually, the stream is still alive because flatMap ignores the complete!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment