Created
June 15, 2017 01:26
-
-
Save eungju/c1a4346f1ee36deaa3931560ab90a642 to your computer and use it in GitHub Desktop.
RxJava 2.1.0+withLatestFrom+cache+firstOrError causes NoSuchElementException
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
@Test | |
fun withLatestFromCausesNoSuchElementException() { | |
val state = Observable.just(42).cacheWithInitialCapacity(1) | |
var error = 0 | |
val threads = (0..4 - 1) | |
.map { | |
Thread { | |
Observable.just(Unit) | |
.withLatestFrom(state, BiFunction { _: Unit, state: Int -> state }) | |
.firstOrError() | |
.subscribe({}, { if (it is NoSuchElementException) error++ }) | |
} | |
} | |
threads.forEach { it.start() } | |
threads.forEach { it.join() } | |
assertThat(error, Matchers.greaterThan(0)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
원인은 모르겠지만 combineLatest로 바꾸거나 state를 먼저 단일 쓰레드에서 subscribe 해주면 피할 수 있어요.