@@ -126,34 +126,30 @@ public final class HeartbeatController {
126126 }
127127 }
128128
129- @available ( iOS 13 . 0 , macOS 10 . 15 , macCatalyst 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * )
130- public func flushAsync( ) async -> HeartbeatsPayload {
131- return await withCheckedContinuation { continuation in
132- let resetTransform = { ( heartbeatsBundle: HeartbeatsBundle ? ) -> HeartbeatsBundle ? in
133- guard let oldHeartbeatsBundle = heartbeatsBundle else {
134- return nil // Storage was empty.
135- }
136- // The new value that's stored will use the old's cache to prevent the
137- // logging of duplicates after flushing.
138- return HeartbeatsBundle (
139- capacity: self . heartbeatsStorageCapacity,
140- cache: oldHeartbeatsBundle. lastAddedHeartbeatDates
141- )
129+ public func flushAsync( completionHandler: @escaping ( HeartbeatsPayload ) -> Void ) {
130+ let resetTransform = { ( heartbeatsBundle: HeartbeatsBundle ? ) -> HeartbeatsBundle ? in
131+ guard let oldHeartbeatsBundle = heartbeatsBundle else {
132+ return nil // Storage was empty.
142133 }
134+ // The new value that's stored will use the old's cache to prevent the
135+ // logging of duplicates after flushing.
136+ return HeartbeatsBundle (
137+ capacity: self . heartbeatsStorageCapacity,
138+ cache: oldHeartbeatsBundle. lastAddedHeartbeatDates
139+ )
140+ }
143141
144- // Asynchronously gets and returns the stored heartbeats, resetting storage
145- // using the given transform.
146- storage. getAndSetAsync ( using: resetTransform) { result in
147- switch result {
148- case let . success( heartbeatsBundle) :
149- // If no heartbeats bundle was stored, return an empty payload.
150- continuation
151- . resume ( returning: heartbeatsBundle? . makeHeartbeatsPayload ( ) ?? HeartbeatsPayload
152- . emptyPayload)
153- case . failure:
154- // If the operation throws, assume no heartbeat(s) were retrieved or set.
155- continuation. resume ( returning: HeartbeatsPayload . emptyPayload)
156- }
142+ // Asynchronously gets and returns the stored heartbeats, resetting storage
143+ // using the given transform.
144+ storage. getAndSetAsync ( using: resetTransform) { result in
145+ switch result {
146+ case let . success( heartbeatsBundle) :
147+ // If no heartbeats bundle was stored, return an empty payload.
148+ completionHandler ( heartbeatsBundle? . makeHeartbeatsPayload ( ) ?? HeartbeatsPayload
149+ . emptyPayload)
150+ case . failure:
151+ // If the operation throws, assume no heartbeat(s) were retrieved or set.
152+ completionHandler ( HeartbeatsPayload . emptyPayload)
157153 }
158154 }
159155 }
0 commit comments