Classes
The following classes are available globally.
-
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
See moreThrowingFuture.Declaration
Swift
public class Future<Wrapped> -
A
Futurewith support for error handling.expensiveComputation().then { print("result: \($0)") }.onError{ print("error: \($0)") }The
!>operator also throws when used with a ThrowingFuture.let result = try !>expensiveComputation()Not handling errors coming from a ThrowingFuture will result in an error.
See moreDeclaration
Swift
public final class ThrowingFuture<Wrapped> : Future<Wrapped>
-
Produces
See moreThrowingFutures that can be completed with a value or error at a later time.Declaration
Swift
public class ThrowingCompleter<Wrapped>
Classes Reference