TaskManager

public class TaskManager

A task manager can be given an arbitrary number of Tasks and initialized with a set of Interceptors and Reactors, after which it will take care of asynchonous task management for you.

  • Shared TaskManager that is default constructed and has no Interceptors or Reactors.

    Declaration

    Swift

    public static let shared: TaskManager
  • List of reactors that this TaskManager was created with

    Declaration

    Swift

    public var reactors: [Reactor] { get }
  • List of interceptors that this TaskManager was created with

    Declaration

    Swift

    public var interceptors: [Interceptor] { get }
  • Identifies the TaskManager in question. It is an atomically increasing integer, per TaskManager created

    Declaration

    Swift

    public let identifier: Int
  • Initializes this manager object.

    Declaration

    Swift

    public init(interceptors: [Interceptor] = [], reactors: [Reactor] = [])

    Parameters

    interceptors

    an array of interceptors that will be applied to every task before being started

    reactors

    an array of reactors that will be applied to every task after it’s executed

  • Add a task to the manager. You may choose to start the task immediately or start it yourself via the Handle that is returned. Additionally, you can also set an interval on when to start the task but that is only valid if startImmediately is set to true

    Declaration

    Swift

    @discardableResult
    public func add<T: Task>(
        task: T,
        startImmediately: Bool = true,
        after interval: DispatchTimeInterval? = nil,
        timeout: DispatchTimeInterval? = nil,
        completeOn completionQueue: DispatchQueue? = nil,
        completion: T.CompletionCallback? = nil
    ) -> Tasker.Handle

    Parameters

    task

    the task to run

    startImmediately

    set this to false if you want to explicity call start on the Handle that’s returned

    after

    set this to some value if you want the task to start running after some interval

    timeout

    after how long the task times out (overrides Task.timeout)

    completeOn

    specifies which queue completion is called on

    completion

    called after the task is done with the result of Task.execute

  • Blocks until all tasks finish executing

    Declaration

    Swift

    public func waitTillAllTasksFinished()