Future
public class Future<Wrapped>
Use a future for doing work asynchronously and returning a result.
A future can represent a value. Receivers of a Future can register callbacks that handle the value a future represents.
func intensiveFunction() -> Future<String> {
return Future {
// Intensive computation
return "Result"
}
}
expensiveFunction().then { result in
print("The result: \(result)")
}
If you want to wait until the future completes, you can use the !> prefix operator:
let value = !>expensiveFunction()
If you need error handling, use a ThrowingFuture.
-
Execute a given closure after the Future has copmleted.
Declaration
Swift
public final func then(closure: (Wrapped) -> ()) -> Self -
Initialize a new future and execute the given closure. The closure is executed asynchronously on a special dispatch queue.
Declaration
Swift
public init(execute closure: () -> (Wrapped))
-
Undocumented
Declaration
Swift
public class Future<Wrapped>
Future Class Reference