How do I - Long polling and Schedulers?

大城市里の小女人 提交于 2020-01-21 10:01:28

问题


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.

  1. Schedule via timer, but only enqueue next iteration if previous iteration has already finished.

  2. 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.

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.


回答1:


Something like this:

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); 


来源:https://stackoverflow.com/questions/37926371/how-do-i-long-polling-and-schedulers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!