Answer the question
In order to leave comments, you need to log in
How to pause and run intrerval in RxJS?
Good afternoon!
Please tell me how to solve this problem. Also, please advise guides on RxJS with simple examples.
export class GameComponent implements OnInit, OnDestroy {
reloadGameInfo = interval(10000);
reloadGameInfoSubscription: Subscription;
stepTimer = interval(1000);
stepTimerSubscription: Subscription;
ngOnInit(){
this.reloadGameInfoSubscription = this.reloadGameInfo.subscribe(() => {
this.gameService.getInfoGame(this.current_game.auth_key)
.subscribe((response: Game) => {
if (this.current_game.status_id == gameStatusCode.two_player_in_game) {
if (!this.stepTimerSubscription) {
this.stepTimerSubscription = this.stepTimer.subscribe(() => {
if (--this.current_game.seconds_for_step == 0) {
this.stepTimerSubscription.unsubscribe();
}
});
}
}
});
});
}
}
Answer the question
In order to leave comments, you need to log in
reloadGameInfo = interval(10000);
stepTimer = interval(1000);
second_to_event = 100;
this.stepTimer.subscribe(() => {
this.second_to_event = this.second_to_event >= 0 ? this.second_to_event - 1 : 0;
if (this.second_to_event === 0) {
// make request at second_to_event equals to 0 and set second_to_event if request success
}
});
this.reloadGameInfo.pipe(
filter(() => this.second_to_event > 0
)
.subscribe(() => {
// do 10000 periodic task
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question