Skip to content

Commit d5c8ee3

Browse files
update sync status sendable status. Update logger usage in tests.
1 parent 19f6c21 commit d5c8ee3

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

Sources/PowerSync/Kotlin/sync/KotlinSyncStatusData.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,17 @@ extension KotlinProgressWithOperationsProtocol {
103103
}
104104
}
105105

106-
struct KotlinProgressWithOperations: KotlinProgressWithOperationsProtocol {
106+
struct KotlinProgressWithOperations: KotlinProgressWithOperationsProtocol,
107+
// We can't mark PowerSyncKotlin.ProgressWithOperations as Sendable
108+
@unchecked Sendable
109+
{
107110
let base: PowerSyncKotlin.ProgressWithOperations
108111
}
109112

110-
struct KotlinSyncDownloadProgress: KotlinProgressWithOperationsProtocol, SyncDownloadProgress {
113+
struct KotlinSyncDownloadProgress: KotlinProgressWithOperationsProtocol, SyncDownloadProgress,
114+
// We can't mark PowerSyncKotlin.SyncDownloadProgress as Sendable
115+
@unchecked Sendable
116+
{
111117
let progress: PowerSyncKotlin.SyncDownloadProgress
112118

113119
var base: any PowerSyncKotlin.ProgressWithOperations {

Sources/PowerSync/Logger.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@ import OSLog
33
/// A log writer which prints to the standard output
44
///
55
/// This writer uses `os.Logger` on iOS/macOS/tvOS/watchOS 14+ and falls back to `print` for earlier versions.
6-
public class PrintLogWriter: LogWriterProtocol {
6+
public final class PrintLogWriter: LogWriterProtocol {
77
private let subsystem: String
88
private let category: String
9-
private lazy var logger: Any? = {
10-
if #available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) {
11-
return Logger(subsystem: subsystem, category: category)
12-
}
13-
return nil
14-
}()
9+
private let logger: Sendable?
1510

1611
/// Creates a new PrintLogWriter
1712
/// - Parameters:
@@ -22,6 +17,12 @@ public class PrintLogWriter: LogWriterProtocol {
2217
{
2318
self.subsystem = subsystem
2419
self.category = category
20+
21+
if #available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) {
22+
logger = Logger(subsystem: subsystem, category: category)
23+
} else {
24+
logger = nil
25+
}
2526
}
2627

2728
/// Logs a message with a given severity and optional tag.

Tests/PowerSyncTests/Kotlin/KotlinPowerSyncDatabaseImplTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ final class KotlinPowerSyncDatabaseImplTests: XCTestCase {
521521

522522
try await db2.close()
523523

524-
let warningIndex = testWriter.logs.firstIndex(
524+
let warningIndex = testWriter.getLogs().firstIndex(
525525
where: { value in
526526
value.contains("warning: Multiple PowerSync instances for the same database have been detected")
527527
}
@@ -542,7 +542,7 @@ final class KotlinPowerSyncDatabaseImplTests: XCTestCase {
542542

543543
try await db2.close()
544544

545-
let warningIndex = testWriter.logs.firstIndex(
545+
let warningIndex = testWriter.getLogs().firstIndex(
546546
where: { value in
547547
value.contains("warning: Multiple PowerSync instances for the same database have been detected")
548548
}

Tests/PowerSyncTests/Kotlin/TestLogger.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
import Foundation
12
@testable import PowerSync
23

4+
final class TestLogWriterAdapter: LogWriterProtocol,
5+
// The shared state is guarded by the DispatchQueue
6+
@unchecked Sendable
7+
{
8+
private let queue = DispatchQueue(label: "TestLogWriterAdapter")
9+
10+
private var logs = [String]()
11+
12+
func getLogs() -> [String] {
13+
queue.sync {
14+
logs
15+
}
16+
}
317

4-
class TestLogWriterAdapter: LogWriterProtocol {
5-
var logs = [String]()
6-
718
func log(severity: LogSeverity, message: String, tag: String?) {
8-
logs.append("\(severity): \(message) \(tag != nil ? "\(tag!)" : "")")
19+
queue.sync {
20+
logs.append("\(severity): \(message) \(tag != nil ? "\(tag!)" : "")")
21+
}
922
}
1023
}
11-

0 commit comments

Comments
 (0)