Also, if I comment out the call to cancel():
public func query(parameters: QueryParameters) async throws -> FeatureQueryResult {
var sub: AnyCancellable?
return try await withTaskCancellationHandler {
//sub?.cancel()
} operation: {
try await withCheckedThrowingContinuation { continuation in
...
sub = myPublisher.sink { completion in
...
continuation.resume(with: myResult)
} receiveValue: { _ in }
}
}
}
Then it compiles but I get a warning:
Variable 'sub' was written to, but never read
Then of course if I don't hold onto the cancellable at all:
public func query(parameters: QueryParameters) async throws -> FeatureQueryResult {
return try await withTaskCancellationHandler {
} operation: {
try await withCheckedThrowingContinuation { continuation in
...
let _ = myPublisher.sink { completion in
...
continuation.resume(with: myResult)
} receiveValue: { _ in }
}
}
}
Then I end up with a runtime error:
SWIFT TASK CONTINUATION MISUSE: queryFeatures(parameters:) leaked its continuation!