I am exploring reactive programming and RxJava. It is fun, but I am stuck on a problem for which I cannot find an answer. My basic question: what is a reactive-appropriate w
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.