简体   繁体   English

Retrofit Call enqueue方法或Rxjava

[英]Retrofit Call enqueue method or Rxjava

As Retrofit docs represent Call enqueue method in Retrofit is : 正如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. 异步发送请求并通知其响应的回调,或者是否发生错误与服务器通信,创建请求或处理响应。

and Rxjava according to this tutorial is : 根据本教程 ,Rxjava是:

RxJava and RxAndroid libraries allow us to easily do async processing using principles of functional reactive programming RxJava和RxAndroid库允许我们使用功能反应式编程原理轻松进行异步处理

it seems these two have the same approach. 似乎这两个人有相同的方法。 What is advantages and disadvantages of each? 每个的优点和缺点是什么? Which one is better to use? 哪一个更好用?

I won't say they have the same approach. 我不会说他们有同样的方法。 Retrofit is specifically designed for API calls which Synchronously or Asynchronously calls an API for you (you can specify that). Retrofit专门为API调用而设计,同步或异步调用API(您可以指定)。 while RxJava & RxAndroid can do the similar for you (ie doing some tasks in sync or async), it is not limited to API call only. 虽然RxJavaRxAndroid可以为您做类似的事情(即同步或异步执行某些任务),但它不仅限于API调用。 You can do many wonders with RxJava/Android 你可以用RxJava/Android做很多奇迹

As you have quoted that 正如你所引用的那样

RxJava and RxAndroid libraries allow us to easily do async processing using principles of functional reactive programming RxJavaRxAndroid库允许我们使用功能反应式编程原理轻松进行异步处理

RxJava & RxAndroid does that with principles of Functional Reactive Programming(FRP). RxJavaRxAndroid使用功能反应式编程(FRP)原理来RxAndroid这一点。 FRP has nothing to do with Retrofit & hence they are not same & can't be compared. FRP与Retrofit无关,因此它们不相同且无法比较。

You can also use RxJava/Android with Retrofit for calling API in FRP Pattern. 您还可以使用RxJava/Android和Retrofit在FRP模式中调用API。

Please read this so you can get more idea about FRP: 请阅读此内容,以便您对FRP有更多了解:

You should read this as well for understanding what operators does RxJava gives & how you could use them 您还应该阅读此内容 ,以了解RxJava提供的操作符以及如何使用它们

In the end, if by Asynchronous you only meant API calls, then Retrofit is better doing that as it's specially designed for that and if by Asynchronous you meant some other tasks like resource intensive or so, then obviously RxJava/Android will be better if you want async task in FRP pattern like Observer or Observable . 最后,如果通过Asynchronous你只是意味着API调用,那么Retrofit更好地做,因为它是专门为此设计的,如果通过Asynchronous你意味着一些其他任务,如资源密集型等,那么显然RxJava/Android会更好,如果你想要像ObserverObservable这样的FRP模式中的异步任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM