Hey,
I want to use the new Publisher Types of the new Combine Framework of iOS 13.
In the session 721 of WWDC 2019 Combine in Practice at about 31:00 or slide 214 Apple uses the type Future
. But currently, there is no Future
Type in the Standard Library. What kind of type do they used to implement an async (network) task in combination with Publisher
?
Example from the WWDC slides:
/// network task
func usernameAvailable(_ username: String, completion: (Bool) -> Void)
@Published var username: String = ""
var validatedUsername: AnyPublisher<String?, Never> {
return $username
//...
.flatMap { username in
return Future { promise in
// promise: (Result<Output, Failure>) -> Void
self.usernameAvailable(username) { available in
promise(.success(available ? username : nil))
}
}
}
.eraseToAnyPublisher()
}