将订阅onError Scala.RX放入一个Observable <closesable>是否有害?

时间:2019-03-14 14:37:05

标签: scala observable scala.rx

我正在理解中使用rx.lang.scala,但是我想快速失败。我还希望在发生异常时关闭资源parameters。如果您抛出Exception / Throwable(如以下示例所示),doOnTerminate是否可以正确执行?

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 个答案:

没有答案