TableEntriesI'm starting out with RxScala and I'm trying to come up with a polling mechanism that checks the database for every interval (say 20 seconds), to check if there was any change in some of the rows in the table.
object MyDatabaseService {
def getAllEntries: List[MyTableEntries] = ???
}
I would need to start out with an Observable that will emit List[MyTableEntries]. So I started out with the following:
class MyDBObservable(service: MyDatabaseService, observer: Observer[Seq[MyTableEntries]]) extends Observable[Seq[MyTableEntries]] {
val o = Observable.interval(10.seconds).map { _ => service.getAllTableEntries }
o.subscribe(observer)
}
In my Observer that I pass in to the function, I have the onNext, onError and onCompleted implemented! There are a couple of questions however:
Is this a valid approach what I have done? Suggestions?
What happens if my database takes more than 30 seconds to respond
Assume the first service.getAllTableEntries
needs 30 seconds, the second and the third service.getAllTableEntries
need 1 seconds.
Then in your example, the first service.getAllTableEntries
happens at 10 seconds, the second one happens at 40 seconds, the third one happens at 41 seconds.
Basically, the events won't be skipped because of the long-running actions. Instead, just delay the events.
What happens if my database is completely down?
If so, I think service.getAllTableEntries
will throw an exception, and you will receive it in onError
.