mirror of
https://github.com/bitwarden/ios.git
synced 2025-12-11 13:54:06 -06:00
22 lines
655 B
Swift
22 lines
655 B
Swift
import Combine
|
|
|
|
extension Future {
|
|
/// Initialize a `Future` with an async throwing closure.
|
|
///
|
|
/// - Parameter attemptToFulfill: A closure that the publisher invokes when it emits a value or
|
|
/// an error occurs.
|
|
///
|
|
convenience init(_ attemptToFulfill: @Sendable @escaping () async throws -> Output) where Failure == Error {
|
|
self.init { promise in
|
|
Task {
|
|
do {
|
|
let result = try await attemptToFulfill()
|
|
promise(.success(result))
|
|
} catch {
|
|
promise(.failure(error))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|