We already know how to handle slow I/O operations. Let's see an example of a long, slow task that is not I/O-bound. For this example, we will modify our loadList()
function and create a new slow
function that will emit our installed apps' items:
private Observable<AppInfo> getObservableApps(List<AppInfo> apps) { return Observable .create(subscriber -> { for (double i = 0; i < 1000000000; i++) { double y = i * i; } for (AppInfo app : apps) { subscriber.onNext(app); } subscriber.onCompleted(); }); }
As you can see, this function performs a few nonsensical computations, only to waste time for the sake of our example, and then it emits our AppInfo
items from the List<AppInfo>
object. Now, we can rearrange our loadList()
function like this:
private void loadList(List<AppInfo> apps) { mRecyclerView.setVisibility...