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
ComponentLifecycleinstance.Declaration
Swift
public init(label: String, logger: Logger? = nil)Parameters
labellabel of the item, useful for debugging.
loggerLoggerto log with. -
Starts the provided
LifecycleTaskarray. Startup is performed in the order of items provided.Declaration
Swift
public func start(_ callback: @escaping (Error?) -> Void)Parameters
callbackThe handler which is called after the start operation completes. The parameter will be
nilon success and contain theErrorotherwise. -
Starts the provided
LifecycleTaskarray. Startup is performed in the order of items provided.Declaration
Swift
public func start(on queue: DispatchQueue, _ callback: @escaping (Error?) -> Void)Parameters
onDispatchQueueto run the handlers callback oncallbackThe handler which is called after the start operation completes. The parameter will be
nilon success and contain theErrorotherwise. -
Starts the provided
LifecycleTaskarray and waits (blocking) untilshutdownis called on another thread. Startup is performed in the order of items provided.Declaration
Swift
public func startAndWait(on queue: DispatchQueue = .global()) throwsParameters
onDispatchQueueto run the handlers callback on -
Shuts down the
LifecycleTaskarray provided instartorstartAndWait. Shutdown is performed in reverse order of items provided.Declaration
Swift
public func shutdown(_ callback: @escaping (Error?) -> Void = { _ in }) -
Waits (blocking) until
shutdownis invoked on another thread.Declaration
Swift
public func wait()
-
Declaration
Swift
public func register(_ tasks: [LifecycleTask])
View on GitHub
Install in Dash
ComponentLifecycle Class Reference