Skip to content

Commit 636276c

Browse files
committed
wip
1 parent d68b18a commit 636276c

2 files changed

Lines changed: 8 additions & 20 deletions

File tree

Sources/SharingGRDBCore/FetchKey.swift

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ public struct FetchKey<Value: Sendable>: SharedReaderKey {
311311
continuation.resumeReturningInitialValue()
312312
return
313313
}
314-
guard !isTesting else {
315-
continuation.resume(with: Result { try database.read(request.fetch) })
316-
return
317-
}
318-
let scheduler: any ValueObservationScheduler = scheduler ?? .async(onQueue: .main)
314+
// guard !isTesting else {
315+
// continuation.resume(with: Result { try database.read(request.fetch) })
316+
// return
317+
// }
318+
let scheduler: any ValueObservationScheduler = scheduler ?? TestImmediateScheduler()
319319
database.asyncRead { dbResult in
320320
let result = dbResult.flatMap { db in
321321
Result {
@@ -345,12 +345,7 @@ public struct FetchKey<Value: Sendable>: SharedReaderKey {
345345
Result { try request.fetch(db) }
346346
}
347347

348-
let scheduler: any ValueObservationScheduler
349-
if isTesting {
350-
scheduler = TestImmediateScheduler()
351-
} else {
352-
scheduler = self.scheduler ?? .async(onQueue: .main)
353-
}
348+
let scheduler = self.scheduler ?? TestImmediateScheduler()
354349
#if canImport(Combine)
355350
let dropFirst =
356351
switch context {
@@ -439,14 +434,6 @@ public struct NotFound: Error {
439434
package struct TestImmediateScheduler: ValueObservationScheduler, Hashable {
440435
package func immediateInitialValue() -> Bool { true }
441436
package func schedule(_ action: @escaping @Sendable () -> Void) {
442-
if Thread.isMainThread {
443-
DispatchQueue.main.sync {
444-
action()
445-
}
446-
} else {
447-
DispatchQueue.main.async {
448-
action()
449-
}
450-
}
437+
action()
451438
}
452439
}

Tests/SharingGRDBTests/FetchAllTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Testing
1212
struct FetchAllTests {
1313
@Dependency(\.defaultDatabase) var database
1414

15+
@MainActor
1516
@Test func concurrency() async throws {
1617
let count = 1_000
1718
try await database.write { db in

0 commit comments

Comments
 (0)