The take_until operator

The take_until operator emits items from its source observable until another observable emits an item. The following figure shows the marble diagram of this operator:

Figure 9.33: The take_until operator

Its prototype is the following:

Observable.take_until(self, other)

Here, other is an observable used to stop emitting items from the source observable.

Here is an example of the take_until operator:

numbers = Subject()
trigger = Subject()

numbers.take_until(trigger).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")
)

numbers.on_next(1)
numbers.on_next(2)
trigger.on_next(True)
numbers.on_next(3)
numbers.on_next(4)
numbers.on_completed()

This example gives the following result:

on_next 1
on_next 2
on_completed
..................Content has been hidden....................

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