Android retofit + rxjava how to handle dynamic request parameter using repeatwhen

I am using retrofit + rxjava to handle the main http get request. And the request will be repeated every 5 seconds. repeatwhen exactly meets the requirement and which works well provided that the query parameter has never changed.

In my test case, the parameter will change at every moment of the request, and the code below does not work.

netInterface
            .postRequest(requestData)
            .repeatWhen(new Func1<Observable<? extends Void>, Observable<?>>() {
                @Override
                public Observable<?> call(Observable<? extends Void> observable) {

                    requestData.setFreeMemory(x);
                    return observable.just(reqeustData).delay(5, TimeUnit.SECONDS);
                }
            })
            .subscribeOn(Schedulers.newThread())
            .observeOn(Schedulers.newThread())
            .subscribe(this.requestSubscriber);
+4
source share
1 answer

- , , , , . , ! , Java. , , !

Observable.combineLatest(getTextToGetObservable, Observable.interval(5, SECONDS)
            .subscribe(netInterface::postRequest)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(this.requestSubscriber);

, , , subscribeOn/observOn. , - , , , .

, , repeatWhen , , (GET POST - , , . ! . , , , , . , , .

Android, , . , , 5 , , . , , . , , . , . , , RxJava .

, , , .

! .

, , , , -, . , , , . .

0

Source: https://habr.com/ru/post/1657730/


All Articles