I have subscribed to timer that produces event every n seconds
Observable.interval(1000)
.startWith(0)
.map( x => { return 'USER'; }
i have also other observable, that produces results that are not available from the very beggining, it takes some time to resolve. The timeout events accumulate, and when the other event finally fires up I have a flood of requests.
.zip(tokenService.token, (privilege: string, token: Token) => {
/*get request body*/ }
.flatMap((body: any) => { /* perform refresh request */ }
.map( x => { return x.json(); })
.subscribe( json => {
let token = json['token']'
tokenService.setToken(token);
});
Is there a way to keep only one last event from timer, and discard the rest?
.last()
does not work for me, because it does return only one event, but then it returns nothing, i don't see next timeout events.
Maybe it is not a good angle for my problem? I want to refresh token every n seconds, and do that only if I have valid token on my hand (right now service providing Observable<Token>
)
Edit: Ok, I found out this is called backpressure, and there is an article about it: https://github.com/ReactiveX/RxJava/wiki/Backpressure
Question still stands though.