RxJava — Terminating Infinite Streams

本小妞迷上赌 提交于 2019-11-30 07:07:49

Since you are initiating the file watching when the subscription is requested, it makes sense to terminate it when the subscription ends, i.e., when the Subscription is closed. This addresses one of the loose ends in your code comments: you return a Subscription which tells the FileWatcher to stop watching the file. Then replace your loop condition such that it checks whether the subscription has been canceled instead of checking whether the current thread has been interrupted.

Problem is, that isn't very helpful if your onSubscribe() method never returns. Perhaps your FileWatcher should require a scheduler to be specified, with the reading occurring on that scheduler.

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