Skip to content

Preserve debounce upstream failure without outstanding demand - #451

Open
Hokila wants to merge 2 commits into
apple:mainfrom
Hokila:fix/debounce-preserve-upstream-error-450
Open

Preserve debounce upstream failure without outstanding demand#451
Hokila wants to merge 2 commits into
apple:mainfrom
Hokila:fix/debounce-preserve-upstream-error-450

Conversation

@Hokila

@Hokila Hokila commented Aug 26, 2026

Copy link
Copy Markdown

Summary

Preserve upstream failures in debounce when there is no outstanding downstream demand.

Root Cause

When the upstream threw while DebounceStateMachine was in waitingForDemand with no buffered element, the state machine transitioned to .finished. This discarded the original error, causing the next call to next() to return nil instead of throwing.

Changes

  • Preserve the upstream error using .upstreamFailure(error:).
  • Continue cancelling the debounce task and clock continuation.
  • Add public API regression tests covering:
    • Upstream failure without producing any element.
    • Failure after an element was produced while downstream had no demand.
    • Non-zero debounce intervals.
    • Preservation of the original error type and value.
    • No additional elements or repeated completion after failure.

Validation

  • swift test --filter TestDebounce
  • swift test
  • swift-format lint --recursive Sources Tests

All checks passed on macOS arm64.

Fixes #450

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.

debounce drops an upstream error when no demand is outstanding

1 participant