Reputation: 2446
I want to check the status of user after particular time delay.
I have two Observables:
Timer Observable: Which emits event after particular delay.
Observable timer = Observable.timer((endTime - startTime), TimeUnit.SECONDS);
Observable
which gets the current status of user.
Observable status = getCurrentStatusObservable(id);
I have to combine these observable sequentially and then result should emit. For implementing this I used zip operator with following approach.
return Observable.zip(timer, status, new Func2<Long, CurrentStatus, CurrentStatus>() {
@Override
public Program call(Long aLong, CurrentStatus status) {
return program;
}
});
But problem is that status
observable
is getting executed before timer
blows. Hence zip
operator is returning status
which is old. But I want status
Observable
to execute after timer
blows.
Please let me know if I am using wrong operator. I checked concat
operator, but it need Observable
of same type.
Upvotes: 1
Views: 480
Reputation: 31438
You can use just a regular flatMap
return timer.flatMap(new Func1<Long, Observable<CurrentStatus>() {
@Override
public Observable<CurrentStatus> call(Long aLong) {
return status;
}
});
Upvotes: 1