Hey guys,
Enabling StrictConcurrency
check raise a warning on our Future
extension:
extension Future where Failure == Error, Output: Sendable {
convenience public init(_ asyncFunction: @escaping @Sendable () async throws -> Output) {
self.init { promise in
Task {
do {
let result = try await asyncFunction()
promise(.success(result))
} catch {
promise(.failure(error))
}
}
}
}
}
The warning is: Capture of 'promise' with non-sendable type '(Result<Output, any Error>) -> Void' in a
@Sendable closure
I'm trying to understand the reason behind. I've read here that
closure must not close over non-Sendable
But why promise
is non-Sendable? Result
is enum
with only Sendable
associated values (both Output
and Failure
)
Looks like I'm still missing key point of @Sendable