Skip to content

Commit cf8eb4c

Browse files
committed
reuse completion handler
1 parent 4fa1e60 commit cf8eb4c

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Sources/MixpanelInstance.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
407407
return
408408
}
409409

410-
taskId = sharedApplication.beginBackgroundTask { [weak self] in
410+
let completionHandler: () -> Void = { [weak self] in
411411
guard let self = self else { return }
412412

413413
#if DECIDE
@@ -421,12 +421,10 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
421421
}
422422
}
423423

424+
taskId = sharedApplication.beginBackgroundTask(expirationHandler: completionHandler)
425+
424426
if flushOnBackground {
425-
flush() { [weak self] in
426-
guard let self = self else { return }
427-
sharedApplication.endBackgroundTask(self.taskId)
428-
self.taskId = UIBackgroundTaskIdentifier.invalid
429-
}
427+
flush(completion: completionHandler)
430428
}
431429
}
432430

0 commit comments

Comments
 (0)