我如何-长轮询和调度程序? [英] How do I - Long polling and Schedulers?
问题描述
我正在尝试安排长轮询机制.我想知道我是否可以利用Scheduler来实现这一点.
I am trying to schedule a long polling mechanism. And I was wondering if I could leverage Schedulers for that.
这是我到目前为止一直在想的事情.
Here's what I have been thinking so far.
-
通过计时器安排时间,但是只有在先前的迭代已经完成的情况下才排队下一个迭代.
Schedule via timer, but only enqueue next iteration if previous iteration has already finished.
在上一次迭代完成时加入下一个迭代.
Enqueue next iteration as previous iteration is finishing.
我一直在研究现有的调度程序,但是我不确定要选择哪个调度程序和超负荷运行的程序.
I have been looking at existing schedulers, but I am not really sure which one to pick and what to overload.
最后但并非最不重要的一点-正如我是Rx世界的新手一样-使用Scheduler相对于自己动手"方法具有什么优势.
And last but not least - as I am a novice in Rx world - what are the advantages that the use of Scheduler would offer vis-a-vis "roll your own" approach.
推荐答案
类似以下内容:
Observable.interval(500)
.exhaustMap(() => this.load()) //previously flatMapFirst, creates new observable only if previous has ended
.map(r => resource.json)
.distinctUntilChanged() //optional tracking changes
.startWith(0);
这篇关于我如何-长轮询和调度程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!