gpt4 book ai didi

android - Retrofit 是否支持 rx.Future/Task/Async/Single?

转载 作者:行者123 更新时间:2023-11-29 19:53:22 26 4
gpt4 key购买 nike

我在 this article 找到了很好的使用 RxJava 的例子:

Subscription subscription = Single.create(new Single.OnSubscribe() {
@Override
public void call(SingleSubscriber singleSubscriber) {
String value = longRunningOperation();
singleSubscriber.onSuccess(value);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1() {
@Override
public void call(String value) {
// onSuccess
Snackbar.make(rootView, value, Snackbar.LENGTH_LONG).show();
}
}, new Action1() {
@Override
public void call(Throwable throwable) {
// handle onError
}
});

但是由于我使用的是 Retrofit,所以我想创建 RetrofitService 并使用 Single 类将两个后端请求的结果组合到一个数据集中,如下所述:

When subscribing to a Single, there is only an onSuccess Action and an onError action. The Single class has a different set of operators than Observable, with several operators that allow for a mechanism of converting a Single to an Observable. For example, using the Single.mergeWith() operator, two or more Singles of the same type can be merged together to create an Observable, emitting the results of each Single to one Observable.

是否有可能实现这一目标(以及如何实现)?

最佳答案

是的,参见 Retrofit Adapters仅适用于 Retrofit2.0

关于android - Retrofit 是否支持 rx.Future/Task/Async/Single?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36909987/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com