Retrofit调用enqueue方法或者Rxjava
Retrofit Call enqueue method or Rxjava
As Retrofit 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
and RxAndroid
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
或 Observable
。
显然 RxJava/Android
会更好
As Retrofit 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
或 Observable
。
RxJava/Android
会更好