Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RxJava 2.1.0+withLatestFrom+cache+firstOrError causes NoSuchElementException
@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))
}
@eungju

This comment has been minimized.

Copy link
Owner Author

@eungju eungju commented Jun 15, 2017

원인은 모르겠지만 combineLatest로 바꾸거나 state를 먼저 단일 쓰레드에서 subscribe 해주면 피할 수 있어요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment