Contents

trackLaunchTask(id:onTrackingError:_:)

Measures the duration of a synchronous extended launch task.

Declaration

@MainActor final func trackLaunchTask<Result, Failure>(id: LaunchTaskID, onTrackingError: ((MetricManager.LaunchTaskError) -> Void)? = nil, _ operation: () throws(Failure) -> Result) throws(Failure) -> Result where Failure : Error

Discussion

Use this method to wrap synchronous work that extends your app’s perceived launch time. Pass a LaunchTaskID and a synchronous closure wrapping the work to measure. Measurement begins when the closure starts and ends it when the closure returns, regardless of whether the closure throws.

manager.trackLaunchTask(id: "register-services") {
    registerAllServices()
}

Pass an onTrackingError closure to observe MetricManager.LaunchTaskError values without interrupting the tracked work:

manager.trackLaunchTask(id: "register-services", onTrackingError: { error in
    logger.warning("Tracking error: \(error.reason)")
}) {
    registerAllServices()
}

This method replaces the paired MXMetricManager.extendLaunchMeasurement(forTaskID:) and MXMetricManager.finishExtendedLaunchMeasurement(forTaskID:) calls. To track asynchronous launch work instead, use trackLaunchTask(id:onTrackingError:_:).

See Also

Extended launch