Skip to content

Instantly share code, notes, and snippets.

@timboudreau
Last active February 4, 2026 05:29
Show Gist options
  • Select an option

  • Save timboudreau/136a63381380d3046fca4c89b7d343ec to your computer and use it in GitHub Desktop.

Select an option

Save timboudreau/136a63381380d3046fca4c89b7d343ec to your computer and use it in GitHub Desktop.
nonisolated and isolated in AppDelegate
fileprivate final class MixenAppDelegate: NSObject, UIApplicationDelegate, MXMetricManagerSubscriber {
nonisolated let registered = AtomicBool()
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Get this out of the critial path of startup, or we will get passed metrics packets to
// process before the main UI is on-screen
if OnboardingState.initial.isReadyForUse {
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 75) {
self.register()
}
}
let configuration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)
configuration.delegateClass = MixenSceneDelegate.self
return configuration
}
nonisolated func register() {
if registered.exchange(true) {
MXMetricManager.shared.add(self)
Logger.metrics.notice("Registered to collect metrics")
}
}
func applicationWillTerminate(_ application: UIApplication) {
MXMetricManager.shared.remove(self)
}
nonisolated func didReceive(_ payloads: [MXMetricPayload]) {
for payload in payloads {
Logger.misc.debug("Received metrics: \(payload.jsonRepresentation())")
if let mmx = MixenMetrics2(payload) {
mmx.send()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment