使用什么 rx 运算符来调用链中间的网络功能?
What rx operator to use to call a network function in the middle of a chain?
我终于掌握了 rx 的诀窍。那么问题来了....
addressSubscription = AppObservable.bindActivity(this, lastKnownLocationObservable
.flatMap(new Func1<Location, Observable<List<Address>>>() {
@Override
public Observable<List<Address>> call(Location location) {
return locationProvider.getGeocodeObservable(location.getLatitude(), location.getLongitude(), 1);
}
})
.map(new Func1<List<Address>, Address>() {
@Override
public Address call(List<Address> addresses) {
return addresses != null && !addresses.isEmpty() ? addresses.get(0) : null;
}
})
.map(new AddressToStringFunc())
CALL A OPERATOR HERE THAT WILL SEND SOME RESULTS FROM THIS
CHAIN OVER THE NETWORK
.subscribeOn(Schedulers.io()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
基本上,如果我在一个链条的中间,什么运营商最好对某个函数进行一些任意调用,然后恢复定期计划的程序....
如果你想做一些有副作用的事情,你可以使用 doXXX 运算符,例如 doOnNext
.
我终于掌握了 rx 的诀窍。那么问题来了....
addressSubscription = AppObservable.bindActivity(this, lastKnownLocationObservable
.flatMap(new Func1<Location, Observable<List<Address>>>() {
@Override
public Observable<List<Address>> call(Location location) {
return locationProvider.getGeocodeObservable(location.getLatitude(), location.getLongitude(), 1);
}
})
.map(new Func1<List<Address>, Address>() {
@Override
public Address call(List<Address> addresses) {
return addresses != null && !addresses.isEmpty() ? addresses.get(0) : null;
}
})
.map(new AddressToStringFunc())
CALL A OPERATOR HERE THAT WILL SEND SOME RESULTS FROM THIS
CHAIN OVER THE NETWORK
.subscribeOn(Schedulers.io()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
基本上,如果我在一个链条的中间,什么运营商最好对某个函数进行一些任意调用,然后恢复定期计划的程序....
如果你想做一些有副作用的事情,你可以使用 doXXX 运算符,例如 doOnNext
.