ReceiveValuesOnSubscription forwards cancellation

Fixes #932
This commit is contained in:
Gwendal Roué committed 2021-03-07 12:10:35 +01:00
1 parent 71083a5586
commit 5400217bb6
1 file changed
+15 -1
+15 -1
View File
@@ -119,8 +119,22 @@ where
subscription.request(currentDemand)
}
case .waitingForRequest, .subscribed, .finished:
case .waitingForRequest, .subscribed:
preconditionFailure()
case .finished:
// We receive the upstream subscription requested by
// `upstream.receive(subscriber: self)` above.
//
// But self has been cancelled since, so let's cancel this
// upstream subscription that has turned purposeless.
//
// This cancellation avoids the bug described in
// https://github.com/groue/GRDB.swift/pull/932
// TODO: write a regression test.
sideEffect = {
subscription.cancel()
}
}
}
}