Я очень старался сказать таймеру RxJS перейти к следующей последовательности, но безрезультатно.Может ли кто-нибудь помочь мне с этим.Я сломал свои мысли о том, как это сделать.Но так и не удалось.Вот пример кода, объясняющего, что я пытаюсь сделать.Я пробовал темы.У меня Независимо от того, что я пытаюсь, кажется, что вы должны как-то выбросить подписку и перезапустить, Даже тогда как ??Мои комментарии в коде ниже должны объяснить, чего я хочу достичь.
import { Component, OnInit } from '@angular/core';
import { timer } from 'rxjs';
import { takeWhile } from 'rxjs/operators';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'testAngular4';
private condition = false;
ngOnInit(): void {
timer(0, 15000).pipe(
takeWhile((val) => {
console.log('inside takeWhile', ' val is ', val);
return val < 30000;
})).subscribe(value1 => {
console.log(' subject subscription value is ', value1);
timer(300, 3000).subscribe((value2) => {
// Do something here
console.log(' inside inner timmer subscribe and value is ', value2);
// How to tell the above timer to emit next value before the 3 seconds
// have elapsed. This would obviously be based on some condition
if (this.condition) {
// Emit the next value in the inner timer sequence above.
// I mean don't wait any longer - move on. Emit
}
});
// How to tell the above timer to emit next value before the 3 seconds
// have elapsed. This would obviously be based on some condition
if (this.condition) {
// Emit the next value in the outer timer sequence above
// I mean don't wait any longer - move on. Emit
}
});
}
}