Gurleen Sethi
Gurleen Sethi

Reputation: 3502

How to get a final result from Observable.fromIterable()?

I am getting a List<> of objects from network. I want to pass all the objects to a function and get a result when all the list is exhausted.

Here is what I am doing right now.

Observable.fromIterable(shortLinksList)
            .filter(shortLinkAlreadyExistsPredicate)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(this::insertLink);

How can I get notified when all the list is exhausted?

Upvotes: 0

Views: 4090

Answers (1)

yosriz
yosriz

Reputation: 10267

If you want just to get notified you can use onCompleted on your Subscriber.
If you want a notification with all the items emitted previously, use toList() operator to collect all items emitted from Observable and get single notification with a list of Objects.

Upvotes: 1

Related Questions