改造调用入队方法或Rxjava [英] Retrofit Call enqueue method or Rxjava

查看:195
本文介绍了改造调用入队方法或Rxjava的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为翻新版文档表示翻新中的呼叫入队方法是:

As Retrofit docs represent Call enqueue method in Retrofit is :

异步发送请求并将其响应通知回调或如果在与服务器对话,创建请求时发生错误,或者处理响应.

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 根据本教程是:

RxJava和RxAndroid库使我们可以轻松进行异步处理使用功能反应式编程的原理

RxJava and RxAndroid libraries allow us to easily do async processing using principles of functional reactive programming

这两个似乎具有相同的方法.每种的优点和缺点是什么?哪个更好用?

it seems these two have the same approach. What is advantages and disadvantages of each? Which one is better to use?

推荐答案

我不会说他们有相同的方法. Retrofit 是专门为API调用而设计的,API调用是为您同步或异步调用API(您可以指定).而 RxJava & RxAndroid 可以为您做类似的事情(即以同步或异步方式执行某些任务),它不仅限于API调用.您可以使用 RxJava/Android

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). while RxJava & RxAndroid can do the similar for you (i.e doing some tasks in sync or async), it is not limited to API call only. You can do many wonders with RxJava/Android

正如您所引用的那样

RxJava RxAndroid 库使我们可以轻松地进行异步处理使用功能反应式编程的原理

RxJava and RxAndroid libraries allow us to easily do async processing using principles of functional reactive programming

RxJava & RxAndroid 遵循功能响应式编程(FRP)的原理进行操作.FRP与 Retrofit &因此它们并不相同&无法比较.

RxJava & RxAndroid does that with principles of Functional Reactive Programming(FRP). FRP has nothing to do with Retrofit & hence they are not same & can't be compared.

您还可以将 RxJava/Android 与Retrofit一起使用,以FRP模式调用API.

You can also use RxJava/Android with Retrofit for calling API in FRP Pattern.

请阅读,以便您了解更多信息玻璃钢:

Please read this so you can get more idea about FRP:

您应该阅读以及了解 RxJava 会给&您将如何使用它们

You should read this as well for understanding what operators does RxJava gives & how you could use them

最后,如果仅使用 Asynchronous 来表示API调用,则 Retrofit 最好这样做,因为它是为此而专门设计的,并且如果是 Asynchronous 表示其他一些任务,例如资源密集型任务,那么如果您想要以FRP模式执行异步任务(例如 Observer ),显然 RxJava/Android 会更好可观察的.

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.

这篇关于改造调用入队方法或Rxjava的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆