I am doing async calls , after 10 seconds for 1 minute that means roughly 6 calls will be made , but Problem is in I want it apply delay
on specific condition
Observable
.just(listOfSomethings_Locally)
.take(1, TimeUnit.MINUTES)
.serialize()
.delaySubscription( // this is confusing part
() ->
Observable.just(listOfItems_Network).take(10,TimeUnit.SECONDS)
)
What i want is to delay the network call for 10 seconds except for first call , and cancel network call after 10 seconds , so i should have exact 6 calls in 1 minute.
EDIT
Due to confusion in scenario here is redefined scenario:
what i have is large list of drivers locally and i want to send request to each of them after every 10 seconds and listen to another subscriber to check if driver didn't canceled it within 10 seconds , this process will go for about 1 minute, if one driver cancel i should immediately send request to next one
Code written so far:
Observable.from(driversGot)
.take(1,TimeUnit.MINUTES)
.serialize()
.map(this::requestRydeObservable) // requesting for single driver from driversGot (it's a network call)
.flatMap(dif ->
Observable.amb(
kh.getFCM().driverCanceledRyde(), // listen for if driver cancel request returns integer
kh.getFCM().userRydeAccepted()) // listen for driver accept returns RydeAccepted object
.map(o -> {
if (o instanceof Integer) {
return new RydeAccepted();
} else if (o instanceof RydeAccepted) {
return (RydeAccepted) o;
}
return null;
}).delaySubscription(10,TimeUnit.SECONDS)
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(fua -> {
if (fua == null) {
UiHelpers.showToast(context, "Invalid Firebase response");
} else if (!fua.getStatus()) { // ryde is canceled because object is empty
UiHelpers.showToast(context, "User canceled ryde");
} else { // ryde is accepted
UiHelpers.showToast(context, "User accepted ryde");
}
}, t -> {
t.printStackTrace();
UiHelpers.showToast(context,"Error sending driver requests");
}, UiHelpers::stopLoading);