Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/AsyncAlgorithms/Debounce/DebounceStateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ struct DebounceStateMachine<Base: AsyncSequence & Sendable, C: Clock>: Sendable
return .none

case .waitingForDemand(let task, .none, let clockContinuation, .none):
// We don't have any buffered element so we can just go ahead
// and transition to finished and cancel everything
self.state = .finished
// We don't have outstanding demand to deliver the error to, so store it
// until the downstream calls next and cancel everything.
self.state = .upstreamFailure(error: error)

return .cancelTaskAndClockContinuation(
task: task,
Expand Down
11 changes: 11 additions & 0 deletions Tests/AsyncAlgorithmsTests/TestDebounce.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ final class TestDebounce: XCTestCase {
}
}

func test_upstreamFailureWithoutOutstandingDemand() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else {
throw XCTSkip("Skipped due to Clock/Instant/Duration availability")
}
validate {
"a^"
$0.inputs[0].debounce(for: .steps(0), clock: $0.clock)
"a,,,^"
}
}

func test_noValues() throws {
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else {
throw XCTSkip("Skipped due to Clock/Instant/Duration availability")
Expand Down