Skip to content

Fix throttle demand buffering and emission scheduling - #28

Merged
Kyle-Ye merged 3 commits into
mainfrom
fix/throttle-demand-and-scheduling
Sep 27, 2026
Merged

Kyle-Ye merged 3 commits into
mainfrom
fix/throttle-demand-and-scheduling

Conversation

@Kyle-Ye

@Kyle-Ye Kyle-Ye commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Throttle drops input received without downstream demand and consumes demand before scheduled output runs. With .max(1) and latest: true, a burst of 1, 2, 3 therefore emits 1 instead of Apple's 3.

Use one pending input, a separate scheduling flag, and the next emission time. Consume demand at delivery, schedule buffered input when demand arrives, and select the first input of each window when latest is false. Also match Combine's subscription delivery order, scheduled closure lifetime, completion handling, and buffer cleanup on cancellation.

Add 13 regression tests for demand exhaustion, pending output, window boundaries, reentrant input, optional input, completion, and object lifetime. The state transitions were checked in the local iOS 17 simulator binary, and all regression tests were run against Apple Combine on macOS 26.6.2.

Handle both absolute file URLs and relative paths in SwiftLint baselines, including macOS temporary-directory aliases. This preserves filtering of existing violations with SwiftLint 0.65.0 and 0.65.1.

Validation with Swift 6.3.3:

  • Full OpenCombine suite: 1,581 tests, 4 skipped, 0 failures.
  • Full Apple Combine compatibility suite: 1,579 tests, 4 skipped, 0 failures.
  • All 34 Throttle tests pass against both implementations with -warnings-as-errors.
  • 26 additional comparison scenarios produce the same values and emission times as Apple Combine.
  • bash utils/lint.sh origin/main: 0 violations with SwiftLint 0.65.0 and 0.65.1, including temporary-directory aliases and paths with spaces.
  • Both SwiftLint versions correctly reject an added trailing-semicolon violation.

Fixes #29.

Related to #25.

@codecov

codecov Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.32%. Comparing base (710ffc9) to head (aad6ce7).

Files with missing lines Patch % Lines
...s/OpenCombine/Publishers/Publishers.Throttle.swift 96.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
- Coverage   96.32%   96.32%   -0.01%     
==========================================
  Files         108      108              
  Lines        8080     8100      +20     
==========================================
+ Hits         7783     7802      +19     
- Misses        297      298       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Kyle-Ye
Kyle-Ye merged commit fa6ba53 into main Sep 27, 2026
9 checks passed
@Kyle-Ye
Kyle-Ye deleted the fix/throttle-demand-and-scheduling branch September 27, 2026 17:15
@piercifani

Copy link
Copy Markdown

Thanks for merging this! Will a version be tagged?

@Kyle-Ye

Kyle-Ye commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

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.

Throttle drops input without demand and emits the wrong latest value

2 participants