Classes
The following classes are available globally.
-
Holder for a result that will be provided later.
CoFuture
and its subclassCoPromise
are the implementation of the Future/Promise approach. They allow to launch asynchronous tasks and immediately returnCoFuture
with its future results. The available result can be observed by thewhenComplete()
callback or byawait()
inside a coroutine without blocking a thread.
See morefunc makeFutureOne(args) -> CoFuture<Response> { let promise = CoPromise<Response>() someAsyncFuncWithCallback { response in . . . do some work . . . promise.success(response) } return promise } func makeFutureTwo(args) -> CoFuture<Response> { queue.coroutineFuture { let future = makeFutureOne(args) . . . do some work . . . let response = try future.await() . . . create result using response . . . return result } } func performSomeWork(args) { let future = makeFutureTwo(args) mainQueue.startCoroutine { . . . do some work . . . let result = try future.await() . . . do some work using result . . . } }
Declaration
Swift
public class CoFuture<Value> : _CoFutureCancellable
extension CoFuture: Hashable
extension CoFuture: Cancellable