作为改造 docs在 Retrofit 中表示 Call enqueue 方法是:
Asynchronously send the request and notify callback of its response or if an error occurred talking to the server, creating the request, or processing the response.
和 Rxjava according to this tutorial是:
RxJava and RxAndroid libraries allow us to easily do async processing using principles of functional reactive programming
这两个似乎有相同的方法。各自的优点和缺点是什么?哪个更好用?
最佳答案
我不会说他们有相同的方法。 Retrofit
专为 API 调用而设计,可以同步或异步地为您调用 API(您可以指定)。虽然 RxJava
和 RxAndroid
可以为您做类似的事情(即同步或异步执行一些任务),但它不仅限于 API 调用。你可以用 RxJava/Android
正如你所引用的那样
RxJava
andRxAndroid
libraries allow us to easily do async processing using principles of functional reactive programming
RxJava
和 RxAndroid
使用函数响应式编程 (FRP) 的原则来做到这一点。 FRP 与 Retrofit
无关,因此它们不相同,无法比较。
您还可以使用 RxJava/Android
和 Retrofit 来调用 FRP 模式中的 API。
请阅读this这样您就可以对 FRP 有更多的了解:
你应该阅读 this以及了解运算符的作用 RxJava
提供的内容以及如何使用它们
最后,如果 Asynchronous
只是指 API 调用,那么 Retrofit
更好,因为它是专门为此设计的,如果 Asynchronous
你的意思是其他一些任务,比如资源密集型等等,那么如果你想要 FRP 模式中的异步任务,比如 Observer
或 ,显然
。RxJava/Android
会更好可观察
关于android - Retrofit调用enqueue方法或者Rxjava,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46088566/