Retrofit Call enqueue method or Rxjava

后端 未结 1 653
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 08:27

As Retrofit docs represent Call enqueue method in Retrofit is :

Asynchronously send the request and notify callback of its response or if an error o

1条回答
  •  -上瘾入骨i
    2020-12-31 09:00

    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

    As you have quoted that

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

    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.

    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:

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

    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.

    0 讨论(0)
提交回复
热议问题