Regular updates

It wouldn't be a proper financial stocks monitor if it was unable to get updates automatically.

To get updates automatically from the Yahoo Finance data, we will use a polling mechanism. It means that the app will check for updates by itself at regular intervals.

We can do that by changing the given part:

yahooService.yqlQuery(query, env)
.toObservable()

We can do so by prepending Observable.interval() to look like this:

Observable.interval(0, 5, TimeUnit.SECONDS)
.flatMap(
i -> yahooService.yqlQuery(query, env)
.toObservable()
)

The following code creates an observable that emits an integer sequence at the specified interval:

Observable.interval(0, 5, TimeUnit.SECONDS)

In this case, it will be every 5 seconds. The first parameter of 0 indicates that the first tick should be done instantly without any waiting (0 second interval for the emitted integer).

Also, we plug in our previous code to fetch the data from Yahoo Service using .flatMap(). In the end, it means that whenever the integer is received from Observable.interval(), the yahooService.yqlQuery() is called to fetch financial stock quotes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.200.71