我正在理解中使用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"))
}