Open
Conversation
commit: |
c5f39d2 to
d604c30
Compare
A pesistent gotcha that folks have with iterating streams is that there can arise a race condition where you want to start consuming a stream, but items have already been sent to it by the time your consumer fires up. The fix is to capture a live subscription _before_ your consumer loop fires up. But this leaves you in a pickle because now you can't use the convenient `each()` helper to do your iteration. This allows the argument to `each()` to either be a stream or a subscription. That way, you can have the best of both worlds.
d604c30 to
b1cc893
Compare
jbolda
approved these changes
Jan 26, 2026
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.
Motivation
A pesistent gotcha that folks have with iterating streams is that there can arise a race condition where you want to start consuming a stream, but items have already been sent to it by the time your consumer fires up.
The fix is to capture a live subscription before your consumer loop fires up. But this leaves you in a pickle because now you can't use the convenient
each()helper to do your iteration, so you have to manually iterate:That's ugly, and you shouldn't have to do it as often as you have to.
Approach
This allows the argument to
each()to either be a stream or a subscription. That way, you can have the best of both worlds. The above becomes:Now you get the nice syntax, but any items that arrive after you subscribe, but before your consumer task spins up are still delivered.