ComponentLifecycle

public class ComponentLifecycle : LifecycleTask
extension ComponentLifecycle: LifecycleTasksContainer

ComponentLifecycle provides a basic mechanism to cleanly startup and shutdown a subsystem in a larger application, freeing resources in order before exiting.

  • Undocumented

    Declaration

    Swift

    public let label: String
  • Creates a ComponentLifecycle instance.

    Declaration

    Swift

    public init(label: String, logger: Logger? = nil)

    Parameters

    label

    label of the item, useful for debugging.

    logger

    Logger to log with.

  • Starts the provided LifecycleTask array. Startup is performed in the order of items provided.

    Declaration

    Swift

    public func start(_ callback: @escaping (Error?) -> Void)

    Parameters

    callback

    The handler which is called after the start operation completes. The parameter will be nil on success and contain the Error otherwise.

  • Starts the provided LifecycleTask array. Startup is performed in the order of items provided.

    Declaration

    Swift

    public func start(on queue: DispatchQueue, _ callback: @escaping (Error?) -> Void)

    Parameters

    on

    DispatchQueue to run the handlers callback on

    callback

    The handler which is called after the start operation completes. The parameter will be nil on success and contain the Error otherwise.

  • Starts the provided LifecycleTask array and waits (blocking) until shutdown is called on another thread. Startup is performed in the order of items provided.

    Declaration

    Swift

    public func startAndWait(on queue: DispatchQueue = .global()) throws

    Parameters

    on

    DispatchQueue to run the handlers callback on

  • Shuts down the LifecycleTask array provided in start or startAndWait. Shutdown is performed in reverse order of items provided.

    Declaration

    Swift

    public func shutdown(_ callback: @escaping (Error?) -> Void = { _ in })
  • Waits (blocking) until shutdown is invoked on another thread.

    Declaration

    Swift

    public func wait()

ComponentLifecycle