Async Await
Async and await functionality is implemented as an extention on TaskManager.shared.
See async(_:completion:)
See await(timeout:block:)
-
Calls an asynchronous function and waits for the result. The function that is passed in must have a completion callback, and this is assumed to be the callback that is called when the asynchronous function is done computing the result, e.g.:
let f = { (done: @escaping (Int) -> Void) -> Void in DispatchQueue.global(qos: .unspecified).async { // Do some long running calculation done(5) } } XCTAssertEqual(try await(f), 5)Declaration
Swift
public func await<T>(timeout: DispatchTimeInterval? = nil, block: @escaping (@escaping (T) -> Void) -> Void) throws -> TParameters
timeouthow long to wait or this function to finish
blockan asynchronous function that has a
donecallback as it’s only parameter. The done callback must take the expected value of the asynchronous operation as its only parameter -
Calls an asynchronous function and waits for completion. The function that is passed in must have a completion callback, and this is assumed to be the callback that is called when the asynchronous function is done.
Declaration
Swift
public func await(timeout: DispatchTimeInterval? = nil, block: @escaping (() -> Void) -> Void) throwsParameters
blockan asynchronous function that has a
donecallback as it’s only parameter. Thedonecallback must be called when the asynchronous operation completes.timeouthow long to wait or this function to finish
-
Calls an asynchronous function and waits for the result. The function that is passed in must have a completion callback, and this is assumed to be the callback that is called when the asynchronous function is done computing the result
Declaration
Swift
public func await<T>(timeout: DispatchTimeInterval? = nil, block: @escaping (@escaping (Result<T, Error>) -> Void) -> Void) throws -> TParameters
blockan asynchronous function that has a
donecallback as it’s only parameter. The done callback must take the expectedResult<T, Error>of the asynchronous operation as its only parametertimeouthow long to wait or this function to finish
-
Curry a function. This is very useful when using async/await on functions that take more than one parameter and end in a callback
Declaration
Swift
public func curry<A, B, C>(_ f: @escaping (A, B) -> C) -> (A) -> ((B) -> C)Parameters
fthe function that takes two parameters
Return Value
A function object that takes the 1st parameter and returns a function object that takes the 2nd parameter
-
Curry a function. This is very useful when using async/await on functions that take more than one parameter and end in a callback
Declaration
Swift
public func curry<A, B, C, D>(_ f: @escaping (A, B, C) -> D) -> (A, B) -> ((C) -> D)Parameters
fthe function that takes three parameters
Return Value
A function object that takes the 1st and 2nd parameters and returns a function object that takes the 3rd parameter
View on GitHub
Async Await Reference