Search code examples
javascriptreactive-programmingrxjsreactive-extensions-js

Rx.Observable.interval with different interval for each event


I have a bunch of events, each of which has to be triggered after the previous one with a delay specific to this event.

Rx.Observable.interval gives a possibility to provide just one interval.

Is there a way to provide different intervals?


Solution

  • The solutions is a modified version of what @NiklasFasching have proposed

       Rx.Observable.from(events)
         .concatMap(function(event) { 
            return Rx.Observable.timer(event.delay);
         })
         .subscribe(...)