Difference between doAfterTerminate and doFinally

天大地大妈咪最大 提交于 2019-12-19 05:06:09

问题


Does anybody knows what is the difference between operators "doAfterTerminate" and "doFinally" in RxJava 2 ?


回答1:


The difference is that doFinally executes the provided Action if the downstream cancels/disposes the sequence in addition to the regular onError or onComplete termination paths. This allows cleaning up and releasing resources by all three means. The operator also guarantees that the action gets executed exactly once per subscription even in case if the onError or onComplete signals race with a cancellation.

In contrast, doAfterTerminate only covers onError and onComplete.

You can emulate doFinally with doAfterTerminate + doOnCancel, however, being split a operation, the action parameters may be both executed and cause problems with non-idempotent cleanup logic.



来源:https://stackoverflow.com/questions/47306699/difference-between-doafterterminate-and-dofinally

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!