Tolerate cancelling before we create our task (#250)

# Motivation
We switched the point in time when we create tasks to the first call to `next()`. This had the side effect that we can now be cancelled before we even created our task. Which by itself is fine but we didn't handle it in the state machines.

# Modification
Adapt the state machines of `debounce`, `zip`, `merge` and `combineLatest` to handle cancellation before `next()`.

# Result
We shouldn't run into these preconditions anymore.
This commit is contained in:
Franz Busch authored and GitHub committed 2023-02-06 17:05:07 +00:00
1 parent bf0ec24bde
commit ca2ac60495
8 files changed
+54 -8

No files matched your search

@@ -583,9 +583,8 @@ struct DebounceStateMachine<Base: AsyncSequence, C: Clock> {
mutating func cancelled() -> CancelledAction? {
switch self.state {
case .initial:
// Since we are transitioning to `merging` before we return from `makeAsyncIterator`
// this can never happen
preconditionFailure("Internal inconsistency current state \(self.state) and received cancelled()")
state = .finished
return .none
case .waitingForDemand:
// We got cancelled before we event got any demand. This can happen if a cancelled task