Skip to content

fix Flow.take waiting for n+1 elements instead of terminating at n#220

Merged
adamw merged 1 commit intomainfrom
fix-take-in-flow
Jan 7, 2026
Merged

fix Flow.take waiting for n+1 elements instead of terminating at n#220
adamw merged 1 commit intomainfrom
fix-take-in-flow

Conversation

@ZbutwialyPiernik
Copy link
Contributor

Previously, take(n) would hang forever if the source had exactly n elements. This happened because it tried to read one more element (to check if it should break) even after taking all n elements it needed.

For example, take(3) on a 3-element stream would:

  1. Take element 1
  2. Take element 2
  3. Take element 3
  4. Try to read element 4... and wait forever

Now it breaks right after taking the n-th element, without trying to read more:

Added test shouldBreakImmediatelyAfterTakingNElements() that verifies we process exactly 3 elements when calling take(3), not 4.

@ZbutwialyPiernik ZbutwialyPiernik changed the title fix flow waiting for n+1 elements instead of terminating at n fix Flow.take waiting for n+1 elements instead of terminating at n Jan 7, 2026
@adamw adamw merged commit 857d62e into main Jan 7, 2026
9 checks passed
@adamw adamw deleted the fix-take-in-flow branch January 7, 2026 13:20
@adamw
Copy link
Member

adamw commented Jan 7, 2026

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants