Skip to content

Commit e67de7f

Browse files
committed
Use concurrency and timers from StreamCore
1 parent 3cd1e8c commit e67de7f

File tree

26 files changed

+49
-470
lines changed

26 files changed

+49
-470
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let package = Package(
2929
],
3030
dependencies: [
3131
.package(url: "https://github.com/apple/swift-docc-plugin", exact: "1.0.0"),
32-
.package(url: "https://github.com/GetStream/stream-core-swift.git", exact: "0.4.1")
32+
.package(url: "https://github.com/GetStream/stream-core-swift.git", branch: "chat-concurrency-and-timers")
3333
],
3434
targets: [
3535
.target(

Sources/StreamChat/ChatClient+Environment.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ extension ChatClient {
7878
_ syncRepository: SyncRepository,
7979
_ webSocketClient: WebSocketClient?,
8080
_ apiClient: APIClient,
81-
_ timerType: Timer.Type
81+
_ timerType: TimerScheduling.Type
8282
) -> ConnectionRepository = {
8383
ConnectionRepository(
8484
isClientInActiveMode: $0,
@@ -103,7 +103,7 @@ extension ChatClient {
103103
}
104104
}
105105

106-
var timerType: Timer.Type = DefaultTimer.self
106+
var timerType: TimerScheduling.Type = DefaultTimer.self
107107

108108
var tokenExpirationRetryStrategy: RetryStrategy = DefaultRetryStrategy()
109109

@@ -132,7 +132,7 @@ extension ChatClient {
132132
_ databaseContainer: DatabaseContainer,
133133
_ connectionRepository: ConnectionRepository,
134134
_ tokenExpirationRetryStrategy: RetryStrategy,
135-
_ timerType: Timer.Type
135+
_ timerType: TimerScheduling.Type
136136
) -> AuthenticationRepository = {
137137
AuthenticationRepository(
138138
apiClient: $0,

Sources/StreamChat/Repositories/AuthenticationRepository.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ class AuthenticationRepository: @unchecked Sendable {
9797
private let apiClient: APIClient
9898
private let databaseContainer: DatabaseContainer
9999
private let connectionRepository: ConnectionRepository
100-
private let timerType: Timer.Type
100+
private let timerType: TimerScheduling.Type
101101

102102
init(
103103
apiClient: APIClient,
104104
databaseContainer: DatabaseContainer,
105105
connectionRepository: ConnectionRepository,
106106
tokenExpirationRetryStrategy: RetryStrategy,
107-
timerType: Timer.Type
107+
timerType: TimerScheduling.Type
108108
) {
109109
self.apiClient = apiClient
110110
self.databaseContainer = databaseContainer

Sources/StreamChat/Repositories/ConnectionRepository.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ class ConnectionRepository: @unchecked Sendable {
2626
private let syncRepository: SyncRepository
2727
private let webSocketClient: WebSocketClient?
2828
private let apiClient: APIClient
29-
private let timerType: Timer.Type
29+
private let timerType: TimerScheduling.Type
3030

3131
init(
3232
isClientInActiveMode: Bool,
3333
syncRepository: SyncRepository,
3434
webSocketClient: WebSocketClient?,
3535
apiClient: APIClient,
36-
timerType: Timer.Type
36+
timerType: TimerScheduling.Type
3737
) {
3838
self.isClientInActiveMode = isClientInActiveMode
3939
self.syncRepository = syncRepository

Sources/StreamChat/Utils/AllocatedUnfairLock.swift

Lines changed: 0 additions & 39 deletions
This file was deleted.

Sources/StreamChat/Utils/Atomic.swift

Lines changed: 0 additions & 59 deletions
This file was deleted.

Sources/StreamChat/Utils/EventBatcher.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protocol EventBatcher: Sendable {
1313
var currentBatch: Batch { get }
1414

1515
/// Creates new batch processor.
16-
init(period: TimeInterval, timerType: Timer.Type, handler: @escaping BatchHandler)
16+
init(period: TimeInterval, timerType: TimerScheduling.Type, handler: @escaping BatchHandler)
1717

1818
/// Adds the item to the current batch of events. If it's the first event also schedules batch processing
1919
/// that will happen when `period` has passed.
@@ -32,7 +32,7 @@ final class Batcher<Item> {
3232
/// The batching period. If the item is added sonner then `period` has passed after the first item they will get into the same batch.
3333
private let period: TimeInterval
3434
/// The time used to create timers.
35-
private let timerType: Timer.Type
35+
private let timerType: TimerScheduling.Type
3636
/// The timer that calls `processor` when fired.
3737
private nonisolated(unsafe) var batchProcessingTimer: TimerControl?
3838
/// The closure which processes the batch.
@@ -44,7 +44,7 @@ final class Batcher<Item> {
4444

4545
init(
4646
period: TimeInterval,
47-
timerType: Timer.Type = DefaultTimer.self,
47+
timerType: TimerScheduling.Type = DefaultTimer.self,
4848
handler: @escaping (_ batch: [Item], _ completion: @escaping @Sendable () -> Void) -> Void
4949
) {
5050
self.period = max(period, 0)

Sources/StreamChat/Utils/StreamConcurrency.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

Sources/StreamChat/Utils/Timers.swift

Lines changed: 0 additions & 132 deletions
This file was deleted.

Sources/StreamChat/WebSocketClient/EventMiddlewares/TypingStartCleanupMiddleware.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TypingStartCleanupMiddleware: EventMiddleware {
1515
/// after `start typing` event.
1616
let emitEvent: (Event) -> Void
1717
/// A timer type.
18-
var timer: Timer.Type = DefaultTimer.self
18+
var timer: TimerScheduling.Type = DefaultTimer.self
1919

2020
/// A list of timers per user id.
2121
@Atomic private var typingEventTimeoutTimerControls: [UserId: TimerControl] = [:]
@@ -34,7 +34,7 @@ class TypingStartCleanupMiddleware: EventMiddleware {
3434
return event
3535
}
3636

37-
_typingEventTimeoutTimerControls {
37+
_typingEventTimeoutTimerControls.mutate {
3838
$0[typingEvent.user.id]?.cancel()
3939
$0[typingEvent.user.id] = nil
4040

0 commit comments

Comments
 (0)