링크모음/rxjava
Retrofit2 에서 Rx사용시 Single 이 더 나을까?
행복한 수지아빠
2017. 8. 24. 15:45
반응형
출처 : https://stackoverflow.com/a/42005735
I'd suggest using a Single
as it is more accurate representation of the data flow: you make a request to the server and the you get either one emission of data OR an error:
Single: onSubscribe (onSuccess | onError)?
For an Observable
you could theoretically get several emissions of data AND an error
Observable: onSubscribe onNext? (onCompleted | onError)?
However, if you are using rx-java2, I'd suggest using a Maybe
instead of Single
. The difference between those two is that Maybe
handles also the case when you get the response from server but it contains no body.
Maybe: onSubscribe (onSuccess | onCompleted | onError)?
반응형