The ignore_elements operator

The ignore_elements operator emits no items. This operator completes when its source observable completes. The following figure shows the marble diagram of this operator:

Figure 9.8: The ignore_elements operator

The prototype of this operator is the following:

Observable.ignore_elements(self)

Here is an example of this operator:

numbers = Observable.from_([1, 2, 3, 4, 5, 6])
numbers.ignore_elements().subscribe(
on_next = lambda i: print("on_next {}".format(i)),
on_error = lambda e: print("on_error: {}".format(e)),
on_completed = lambda: print("on_completed")
)

This gives the following result:

on_completed

It is not visible in this example, but the observable returned by the ignore_elements operator completes when the numbers observable completes. This operator is useful in cases where the completion is the only meaningful information. For example, one can wait for completion of the observable before subscribing to another observable (typically with the concat operator). In such a case, the resulting observable emits the items of the second observable but only once the first observable has completed.

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

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