Convert infinite async callback sequence to Observable sequence?

限于喜欢 提交于 2019-12-05 18:05:18
user3743222

You seem to be repeating an action every time it finishes. That looks like a good use case for expand or repeatWhen.

Typically, that would be something like :

Rx.Observable.just(false).expand(_ => {  
  return cancelled ? Rx.Observable.empty() : Rx.Observable.fromCallback(asyncAction)
})

You put cancelled to true at any point of time and when the current action finishes, it stops the loop. Haven't tested it so I would be interested to know if that worked in the end.

You can have a look at similar questions about polling:

Documentation:

Documentation links are for Rxjs 4 but there should not be much changes vs v5

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