Skip to content

Commit 36d81b5

Browse files
committed
Make HeartbeatController also conform to Sendable
1 parent 4eb6a37 commit 36d81b5

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatController.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Foundation
1616

1717
/// An object that provides API to log and flush heartbeats from a synchronized storage container.
18-
public final class HeartbeatController {
18+
public final class HeartbeatController: Sendable {
1919
/// Used for standardizing dates for calendar-day comparison.
2020
private enum DateStandardizer {
2121
private static let calendar: Calendar = {
@@ -31,11 +31,11 @@ public final class HeartbeatController {
3131
}
3232

3333
/// The thread-safe storage object to log and flush heartbeats from.
34-
private let storage: HeartbeatStorageProtocol
34+
private let storage: any HeartbeatStorageProtocol
3535
/// The max capacity of heartbeats to store in storage.
36-
private let heartbeatsStorageCapacity: Int = 30
36+
private static let heartbeatsStorageCapacity: Int = 30
3737
/// Current date provider. It is used for testability.
38-
private let dateProvider: () -> Date
38+
private let dateProvider: @Sendable () -> Date
3939
/// Used for standardizing dates for calendar-day comparison.
4040
private static let dateStandardizer = DateStandardizer.self
4141

@@ -51,7 +51,7 @@ public final class HeartbeatController {
5151
/// - Parameters:
5252
/// - id: The id to associate this controller's heartbeat storage with.
5353
/// - dateProvider: A date provider.
54-
convenience init(id: String, dateProvider: @escaping () -> Date) {
54+
convenience init(id: String, dateProvider: @escaping @Sendable () -> Date) {
5555
let storage = HeartbeatStorage.getInstance(id: id)
5656
self.init(storage: storage, dateProvider: dateProvider)
5757
}
@@ -61,7 +61,7 @@ public final class HeartbeatController {
6161
/// - storage: A heartbeat storage container.
6262
/// - dateProvider: A date provider. Defaults to providing the current date.
6363
init(storage: HeartbeatStorageProtocol,
64-
dateProvider: @escaping () -> Date = Date.init) {
64+
dateProvider: @escaping @Sendable () -> Date = Date.init) {
6565
self.storage = storage
6666
self.dateProvider = { Self.dateStandardizer.standardize(dateProvider()) }
6767
}
@@ -76,7 +76,7 @@ public final class HeartbeatController {
7676

7777
storage.readAndWriteAsync { heartbeatsBundle in
7878
var heartbeatsBundle = heartbeatsBundle ??
79-
HeartbeatsBundle(capacity: self.heartbeatsStorageCapacity)
79+
HeartbeatsBundle(capacity: Self.heartbeatsStorageCapacity)
8080

8181
// Filter for the time periods where the last heartbeat to be logged for
8282
// that time period was logged more than one time period (i.e. day) ago.
@@ -109,7 +109,7 @@ public final class HeartbeatController {
109109
// The new value that's stored will use the old's cache to prevent the
110110
// logging of duplicates after flushing.
111111
return HeartbeatsBundle(
112-
capacity: self.heartbeatsStorageCapacity,
112+
capacity: Self.heartbeatsStorageCapacity,
113113
cache: oldHeartbeatsBundle.lastAddedHeartbeatDates
114114
)
115115
}
@@ -126,15 +126,15 @@ public final class HeartbeatController {
126126
}
127127
}
128128

129-
public func flushAsync(completionHandler: @escaping (HeartbeatsPayload) -> Void) {
130-
let resetTransform = { (heartbeatsBundle: HeartbeatsBundle?) -> HeartbeatsBundle? in
129+
public func flushAsync(completionHandler: @escaping @Sendable (HeartbeatsPayload) -> Void) {
130+
let resetTransform = { @Sendable (heartbeatsBundle: HeartbeatsBundle?) -> HeartbeatsBundle? in
131131
guard let oldHeartbeatsBundle = heartbeatsBundle else {
132132
return nil // Storage was empty.
133133
}
134134
// The new value that's stored will use the old's cache to prevent the
135135
// logging of duplicates after flushing.
136136
return HeartbeatsBundle(
137-
capacity: self.heartbeatsStorageCapacity,
137+
capacity: Self.heartbeatsStorageCapacity,
138138
cache: oldHeartbeatsBundle.lastAddedHeartbeatDates
139139
)
140140
}

FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Foundation
1616

1717
/// A type that can perform atomic operations using block-based transformations.
18-
protocol HeartbeatStorageProtocol {
18+
protocol HeartbeatStorageProtocol: Sendable {
1919
func readAndWriteSync(using transform: (HeartbeatsBundle?) -> HeartbeatsBundle?)
2020
func readAndWriteAsync(using transform: @escaping @Sendable (HeartbeatsBundle?)
2121
-> HeartbeatsBundle?)

FirebaseCore/Internal/Sources/HeartbeatLogging/_ObjC_HeartbeatController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class _ObjC_HeartbeatController: NSObject {
4949
///
5050
/// - Note: This API is thread-safe.
5151
/// - Returns: A heartbeats payload for the flushed heartbeat(s).
52-
public func flushAsync(completionHandler: @escaping (_ObjC_HeartbeatsPayload) -> Void) {
52+
public func flushAsync(completionHandler: @escaping @Sendable (_ObjC_HeartbeatsPayload) -> Void) {
5353
// TODO: When minimum version moves to iOS 13.0, restore the async version
5454
// removed in #13952.
5555
heartbeatController.flushAsync { heartbeatsPayload in

0 commit comments

Comments
 (0)