gpt4 book ai didi

rx-java - 清除 : Would an Observable notify onComplete() after it calls onError()?

转载 作者:行者123 更新时间:2023-12-02 01:02:10 24 4
gpt4 key购买 nike

我需要在流完成时释放资源,无论是 onError 还是 onComplete。阅读自 ReactiveX The Observable Contract在通知上说

An Observable may make zero or more OnNext notifications, each representing a single emitted item, and it may then follow those emission notifications by either an OnCompleted or an OnError notification, but not both.



将清理调用放在 onError 和 onComplete 通知中是否正确?像这样:
.subscribe(
//onNext
completable -> Log.d(LOG_TAG,"done"),
//onError
throwable -> {
Log.d(LOG_TAG,"error");
serviceCleanup();
},
//onComplete
this::serviceCleanup
);

例如。只是为了将来的文档目的,所以我可以向其他人和我自己解释。

最佳答案

您最好使用 doFinallydoAfterTerminate用于资源清理。

关于rx-java - 清除 : Would an Observable notify onComplete() after it calls onError()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49848473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com