Skip to content

Instantly share code, notes, and snippets.

@eungju
Created June 15, 2017 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eungju/c1a4346f1ee36deaa3931560ab90a642 to your computer and use it in GitHub Desktop.
Save eungju/c1a4346f1ee36deaa3931560ab90a642 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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