Skip to content

Instantly share code, notes, and snippets.

@bherbst
Last active December 11, 2017 16:54
Show Gist options
  • Save bherbst/edef0c07cb583b298e6a7257ed7db9ca to your computer and use it in GitHub Desktop.
Save bherbst/edef0c07cb583b298e6a7257ed7db9ca to your computer and use it in GitHub Desktop.
RxJava AutoConnect global error handler
val sharedSource = Observable.just(1)
.delay(1, TimeUnit.SECONDS)
.map { _ ->
// Some operation that throws an exception
throw Exception()
}
.publish()
.autoConnect(2)
val disposable = CompositeDisposable()
disposable.addAll(
sharedSource.subscribe(
{ System.out.println("$it") },
{ it.printStackTrace() }
),
sharedSource.subscribe(
{ System.out.println("$it") },
{ it.printStackTrace() }
)
)
disposable.clear()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment