Is it harmful to throw in the subscribe onError Scala.RX an Observable<Closable>?

29 Views Asked by At

I am using an rx.lang.scala in a for-comprehension, which i want to fail fast. I also want the resource parameters to be closed if an exception occurs. Will the doOnTerminate execute properly if you throw the Exception / Throwable, as in the example provided below?

private def createAgreement(parameters: Params, output: ByteArrayOutputStream): Try[Unit] = Try {
output
  .usedIn(AgreementCreator(parameters).createAgreement) //Observable.using(resource)(observableFactory, t => { dispose(t); IOUtils.closeQuietly(t) }, disposeEagerly)
  .doOnTerminate(parameters.close()) //close resource
  .toBlocking
  .subscribe(_ => {},
    e => throw e,
    () => debug("completed"))
}
0

There are 0 best solutions below