How to have one subscribe for many timers?

Viewed 79

I have array of milliseconds: [3 * 1000, 30 * 1000, 10 * 1000].

When the millisecond event is ready then I log into the console:

milliseconds.forEach(m => {

  timer(m).subscribe(r => { console.log('notification!!'); });
});

Is there a way to make one subscribe for get the events in the right time?

1 Answers

You can try something like this

merge(milliseconds.map(t => timer(t))
.subscribe(r => { console.log('notification!!');

Consider that the merge used here is the merge function imported from rxjs and not the merge operator imported from rxjs/operators

Related