javascript - Passing a non-standard Scheduler to an operator -


let's want pass scheduler rxjs operator makes emit notifications every 5 seconds. of course, easy using interval or other existing operators. if want use scheduler accomplish that, how go it?

my first thought subclass rx.scheduler.default. way go? , if so, how subclass look? again, understand complicated way accomplish that's easy using operators, curious custom schedulers.

operations should independent of schedulers used implement them. schedulers know 1 thing, time. every scheduler built deal own notion of time. expressly not built handle specific operators since conflation of concerns.

so stated goal of creating recurring task, wouldn't recommend trying create own scheduler, isn't needed. schedulers come interface supports this.

you can use either scheduleperiodic or schedulerecursivefuture accomplish this.

//using periodic rx.observable.interval = function(period, scheduler) {    return rx.observable.create(function(observer) {     return scheduler.scheduleperiodic(0, period, function(count) {       observer.onnext(count);       return count + 1;     });   });  };  //using schedulerecursive rx.observable.interval = function(period, scheduler) {    return rx.observable.create(function(observer) {     return scheduler.schedulerecursivefuture(0, period, function(count, self) {       observer.onnext(count);       self(period, count + 1);      });   }); }; 

reference 1, reference 2;

the former should easier wrap head around, scheduling occur repeatedly spaced in time based on period parameter.

the latter little more difficult explain, scheduling task , sometime during execution of task rescheduling (which self parameter) doing. allows same effect using period parameter.

the timing of work directly affected scheduler decide pass operator. instance, if pass in default try use best method asynchronous completion, whether settimeout, setinterval or other thing can't remember. if pass in testscheduler or historicalscheduler won't until increment each of respective clocks, doing gives fine grained control on how time flows.

tl;dr implement new schedulers if have new overall notion of time express, otherwise use existing api work on whatever scheduler best fits how want time pass.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -