AnyTask
public class AnyTask<T> : Task
An AnyTask can be used as a generic Task
object. 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.
AnyTask
s schedules execution blocks on TaskManager.shared
.
-
Alias of the “successful” return value of your execution block
Declaration
Swift
public typealias SuccessValue = T
-
Initialize the AnyTask with an execution block that is given a “done” callback that must be called with a
Task.CompletionCallback
Declaration
Swift
@discardableResult public init(timeout: DispatchTimeInterval? = nil, execute: @escaping (@escaping AnyTask.CompletionCallback) -> Void)
Parameters
timeout
after how long the task timeout
execute
the execution block.
-
Initialize the AnyTask with an execution block that just returns a type T and may throw
Declaration
Swift
@discardableResult public convenience init(timeout: DispatchTimeInterval? = nil, execute: @escaping () throws -> T)
Parameters
timeout
after how long the task timeout
execute
the execution block.
-
Initialize the AnyTask with an execution block that just returns a type T
Declaration
Swift
@discardableResult public convenience init(timeout: DispatchTimeInterval? = nil, execute: @escaping () -> T)
Parameters
timeout
after how long the task timeout
execute
the execution block.
-
Initialize the AnyTask with another
Task
object. TheTask.SuccessValue
must match the type T of this AnyTaskDeclaration
Swift
@discardableResult public convenience init<U>(fromTask task: U, timeout: DispatchTimeInterval? = nil) where T == U.SuccessValue, U : Task
Parameters
task
The
Task
object that this will wraptimeout
Specify if you wan to overwrites
Task.timeout
. -
The timeout passed in the initializer
Declaration
Swift
public let timeout: DispatchTimeInterval?
-
The
Task.execute
function calls the execution block was given to an initilzerDeclaration
Swift
public func execute(completion: @escaping CompletionCallback)