Skip to content

L21 Streams and subscriptions

22 minSuggested first: L20 Reactive dependencies

Outcome

Follow values through an operator and identify the effect of completion or unsubscribe.

Learn

A stream can deliver values over time. A subscription connects an observer to a producer. An operator can transform or filter what reaches the observer. Completion ends delivery normally; an error ends it abnormally.

Unsubscribing stops future delivery to that observer. Don't assume it sends a completion notification, or stops shared upstream work.

Worked example

The source emits 1, 2 and 3, then completes. map doubles each value, then filter keeps values greater than 3. What does the observer see?

A toy streamText
Source:    1  2  3  complete
After map: 2  4  6  complete
Observer:     4  6  complete
Predict first, then show the worked explanation

Doubling gives 2, 4 and 6; the filter drops 2, so the observer sees 4, 6, then completion. If you reverse the two operators, no source value passes the filter first, so the observer sees only completion.

Practice and check

Guided practice

Practice, not scored

If the filter keeps values greater than 4 instead, which value is delivered?

Choose one answer

Exit check

Counts toward completion

In a timed version of the same stream, the observer unsubscribes right after receiving 4, before the source emits 3. Which notification can still reach this observer from this subscription?

Choose one answer

Common mistake

Assuming every stream is asynchronous, shared, or replayed. Check the producer and the exact subscription behavior.

Practice on a real repository

Try the first puzzle below; after it, return to the second if you skipped it in L11.

Related topics: Observables

Practice is optional. Solving a puzzle doesn't complete a lesson, and lessons never change a puzzle's points.

References