c# - What is the correct way to schedule periodic events in Rx? -
simple question, hope: i'm writing application in want retrieve info database; i've elected utilize rx purpose represent database sequence of values.
i want poll database (and have observer's notifications occur) @ maximum of 1 time every 5 seconds. right now, have this, scheduler scheduling periodic task causes observer subscribed observable database:
_scheduler.schedulerperiodic(_repository, timespan.fromseconds(5), (repo) => repo.asobservable() .where(item => _somefilter(item)) .subscribe(item => _someprocessfunction(item)) ); function names , omitted brevity; repo.asobservable() function returns iobservable<t> of items within repository @ point.
now, figure right way of doing things, before came solution did come different solution in had observable.timer subscribed observer subscribe asobservable() homecoming value every timer tick instead.
my question seems very.. odd - why subscribing multiple times observable?
sorry if question confusing, confused me while writing it, schedulers confusing me :p
what if utilize built in operators instead of manually scheduling tasks?
repo.asobservable() .where(_somefilter) // wait 5 seconds before completing .concat(observable.empty<t>().delay(timespan.fromseconds(5)) // resubscribe indefinitely after source completes .repeat() // subscribe .subscribe(_someprocessfunction); c# system.reactive
No comments:
Post a Comment