Skip to content

Commit

Permalink
Fix pagings with headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Aug 27, 2016
1 parent ffc5544 commit e9fa2de
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.List;

import com.microsoft.rest.ServiceResponseWithHeaders;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Func1;
Expand Down Expand Up @@ -45,6 +46,26 @@ public static <E> ServiceCall<List<E>> create(Observable<ServiceResponse<Page<E>
return serviceCall;
}

public static <E, V> ServiceCall<List<E>> createWithHeaders(Observable<ServiceResponseWithHeaders<Page<E>, V>> first, final Func1<String, Observable<ServiceResponseWithHeaders<Page<E>, V>>> next, final ListOperationCallback<E> callback) {
final AzureServiceCall<List<E>> serviceCall = new AzureServiceCall<>();
final PagingSubscriber<E> subscriber = new PagingSubscriber<>(serviceCall, new Func1<String, Observable<ServiceResponse<Page<E>>>>() {
@Override
public Observable<ServiceResponse<Page<E>>> call(String s) {
return next.call(s)
.map(new Func1<ServiceResponseWithHeaders<Page<E>, V>, ServiceResponse<Page<E>>>() {
@Override
public ServiceResponse<Page<E>> call(ServiceResponseWithHeaders<Page<E>, V> pageVServiceResponseWithHeaders) {
return pageVServiceResponseWithHeaders;
}
});
}
}, callback);
serviceCall.setSubscription(first
.single()
.subscribe(subscriber));
return serviceCall;
}

/**
* The subscriber that handles user callback and automatically subscribes to the next page.
*
Expand Down

0 comments on commit e9fa2de

Please sign in to comment.