In this lecture, we are going to learn about the Con Cap Map operator for queuing observables.
It's another operator for flattening and observable inner observables are automatically subscribed by
this operator.
Values emitted by the inner observable are pushed to the stream similar to the Switch map.
Operator This operator will limit the number of active observables to one.
However, the most significant difference is how it treats newer subscriptions.
Instead of cancelling the previous observable, this operator will place observables into a queue.
The next observable in the queue will not be subscribed to until the current active observable has been
completed.
In this example, the interval operator will push values forever.
If a new observable is created, it'll be cued.
Theoretically, the newer observable will never receive a subscription.
Since the first observable never completes, this operator can be helpful when you want to give every
observable a chance to emit values.
Be warned If inner observable are left unmanaged, you can potentially face a traffic jam of observables.
Let's look at an example of how can count map operator works.
First, we need to import this operator.
Update the import statement to include the Icon Cap Map operator.
Next, we will replace the Switch map operator with the Icon Cap Map operator.
Let's test our application with throttling turned on.
Let's click the button five times each request will be performed one at a time.
The next request does not begin until the previous request has been completed.
They're being cued by the Con Cap Map operator.
Overall, the Con Cap Map Operator is great for queuing observables with a finite lifespan.
We can have the best of both worlds by maintaining a single active observable without cancelling previous
observables.
We are still responsible for completing them.
Be sure to manage or observables with this operator.
Otherwise, other observables may not be able to run in the next lecture.
We are going to explore one more flattening operator.