Skip to content

fix(takeLast): handle Infinity count - #7635

Open
yowainwright wants to merge 1 commit into
ReactiveX:masterfrom
yowainwright:fix/take-last-infinity-v9
Open

yowainwright wants to merge 1 commit into
ReactiveX:masterfrom
yowainwright:fix/take-last-infinity-v9

Conversation

@yowainwright

Copy link
Copy Markdown

Description

takeLast(Infinity) currently allocates new Array(Infinity), which throws RangeError: Invalid array length.

This update assigns a growable buffer only for Infinity, while preserving the existing finite-count ring buffer and non-positive early-complete behavior.

  • The regression test verifies that values are still emitted on completion.

Related issue (if exists)

@lbesecker195 lbesecker195 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traced the ring-buffer math for amount = Infinity: counter % Infinity is counter for every finite counter, start resolves to 0, and total becomes counter, so the completion loop emits every buffered value in order. Only the allocation needed to change. Test covers it. LGTM.

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