AnyTask
-
An AnyTask can be used as a generic
Taskobject. You have to pass it a execute block when it’s initialized and that will be called when it’s time to execute the task.
See moreAnyTasks schedules execution blocks onTaskManager.shared.Declaration
Swift
public class AnyTask<T> : Task -
Creates a task out of an expression and returns it as an
AnyTasklet x = task(someLongOperation()) x.async { result in // stuff } // or let result = x.await()Declaration
Swift
public func task<R>(closingOver closure: @autoclosure @escaping () -> R) -> AnyTask<R>Parameters
closingOverthe expression to create a task out of
-
Creates a task out of a function that has a
donecallback. I.e.let f = { (done: @escaping () -> Void) -> Void in DispatchQueue.global(qos: .unspecified).async { // Do some long running calculation done() } } let t = task(executing: f)Declaration
Swift
public func task(executing block: @escaping (@escaping () -> Void) -> Void) -> AnyTask<Void>Parameters
executingan asynchronous function that has a
donecallback as it’s only parameter. Thedonecallback must be called when the asynchronous operation completes. -
Creates a task out of a function that has a
donecallback with a specific signatureDeclaration
Swift
public func task<T>(executing block: @escaping (@escaping (T) -> Void) -> Void) -> AnyTask<T>Parameters
executingan 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 -
Creates a task out of a function that has a
donecallback with a specific signatureDeclaration
Swift
public func task<T>(executing block: @escaping (@escaping (Result<T, Error>) -> Void) -> Void) -> AnyTask<T>Parameters
executingan 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 parameter
View on GitHub
AnyTask Reference