docs: explain how to parallelize work within a single stream - #810
Merged
Conversation
The "CPU Concurrency" guide only demonstrated concurrency across independent pipelines, and never stated that the items of a single pipeline are delivered one at a time. Readers reasonably concluded that adding observe_on(ThreadPoolScheduler(n)) would process items in parallel, and reported the resulting sequential execution as a bug. Add a "Parallelizing Work Within a Single Stream" section showing the flat_map fan-out pattern, note the ordering and max_concurrent trade-offs, and cross-reference it from the observe_on discussion and docstring. Closes #713. Same underlying question as #67, #100 and #528. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #713.
Problem
The "CPU Concurrency" section of the getting-started guide demonstrates concurrency across three independent pipelines, but never states that the items of a single pipeline are delivered one at a time. Readers reasonably conclude that adding
observe_on(ThreadPoolScheduler(n))will process items in parallel, then report the resulting sequential execution as a scheduler bug.This is by design —
ScheduledObserverdrains one notification at a time to honour the Rx contract thaton_nextnever overlaps — but nothing in the docs says so. It has come up repeatedly: #713, #67, #100, #528.Changes
docs/get_started.rst— new "Parallelizing Work Within a Single Stream" section showing the sequential-vs-parallel comparison and theflat_mapfan-out pattern (both thejust(...)+subscribe_onform and the more directfrom_callable(..., scheduler=...)form), plus a note on theconcat_mapordering trade-off andmerge(max_concurrent=...).docs/get_started.rst— an.. important::admonition in the existingsubscribe_on/observe_ondiscussion, linking to the new section.reactivex/operators/_observeon.py— matching note in theobserve_ondocstring, so the clarification is reachable from the API reference and from IDE tooltips.No library behaviour changes.
Verification
Every snippet was executed against this branch. With a 2-second
intense_calculationover three items:observe_on(pool)+mapflat_map+subscribe_on(pool)flat_map+from_callable(..., scheduler=pool)concat_map+from_callable(..., scheduler=pool)which matches what the new section claims, including the ordering caveat.
sphinx-build -W --keep-goingproduces 67 warnings on this branch and 67 onmaster— no new ones.ruff check,ruff format --checkandpyrightpass clean on the changed module, andtests/test_observable/test_observeon.pypasses.🤖 Generated with Claude Code