Reputation: 205
I would like to change dynamically the Observable timer setting.
this.speed = 1000;
let timer = Observable.timer(1, this.speed);
sub = timer.subscribe(t => {
if (t == 10) {
this.speed = 500;
}
});
If for example, after X seconds, I set the this.speed = 500
.
The example above doesn't work. Is it possible, or I have to unsubscribe this one and create a new one?
Upvotes: 1
Views: 1113
Reputation:
You could try this :
createDelayedObservable(delay: number): Observable<any> {
return Observable.of('value').delay(delay);
}
sub = createDelayedObservable(1000).subscribe(res => {/* ... */ });
Upvotes: 1
Reputation: 68655
Observable is currently created with the given time. You can't change that given time to affect the observable. So you need to unsubscribe and create another one.
Upvotes: 1