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.
This change makes
Sequence
behave likeBatch
in how it handlesnil
entries, preventing a possible infinite loop.Background
I stumbled across this discrepancy when I noticed a bubbletea program I had written had CPU usage over 100% all the time, when I would expect it near zero as a CLI simply waiting for input.
I created a simplified repro, and noticed that swapping in
tea.Batch
fortea.Sequence
fixed the CPU usage, which was nice, but it seems like either one should work.Digging in, it looks like
Batch
already had logic to handle all nils in #217 and more recently to return the only non-nil entry directly if possible in #875. This change reuses the same logic (and tests) forSequence
as well now, which avoids creating this infinite loop when usingSequence
👍Demo of Fix
Here's a walk through showing the fix in action within a go workspace.
Here's showing the CPU issue before:
And here's showing it's fixed using this branch:
Let me know your thoughts and if you need this PR adjusted in any way, cheers.