OnDemandFuture fulfill is Sendable

This commit is contained in:
Gwendal Roué committed 2024-07-27 16:37:33 +02:00
1 parent f13b2d2eb4
commit 2aabc4c10e
3 files changed
+13 -8

No files matched your search

+3 -5
View File
@@ -555,11 +555,9 @@ extension DatabaseReader {
value: @escaping (Database) throws -> Output)
-> DatabasePublishers.Read<Output>
{
Deferred {
Future { fulfill in
self.asyncRead { dbResult in
fulfill(dbResult.flatMap { db in Result { try value(db) } })
}
OnDemandFuture { fulfill in
self.asyncRead { dbResult in
fulfill(dbResult.flatMap { db in Result { try value(db) } })
}
}
.receiveValues(on: scheduler)
+7 -3
View File
@@ -14,9 +14,12 @@ import Foundation
/// Both two extra scheduling guarantees are used by GRDB in order to be
/// able to spawn concurrent database reads right from the database writer
/// queue, and fulfill GRDB preconditions.
///
/// OnDemandFuture also adds Sendable requirements that avoid
/// compiler warnings.
@available(iOS 13, macOS 10.15, tvOS 13, *)
struct OnDemandFuture<Output, Failure: Error>: Publisher {
typealias Promise = (Result<Output, Failure>) -> Void
typealias Promise = @Sendable (Result<Output, Failure>) -> Void
typealias Output = Output
typealias Failure = Failure
fileprivate let attemptToFulfill: (@escaping Promise) -> Void
@@ -34,8 +37,9 @@ struct OnDemandFuture<Output, Failure: Error>: Publisher {
}
@available(iOS 13, macOS 10.15, tvOS 13, *)
private class OnDemandFutureSubscription<Downstream: Subscriber>: Subscription {
typealias Promise = (Result<Downstream.Input, Downstream.Failure>) -> Void
private class OnDemandFutureSubscription<Downstream: Subscriber>: Subscription, @unchecked Sendable {
// @unchecked because `state` is protected with `lock`.
typealias Promise = @Sendable (Result<Downstream.Input, Downstream.Failure>) -> Void
private enum State {
case waitingForDemand(downstream: Downstream, attemptToFulfill: (@escaping Promise) -> Void)
+3
View File
@@ -97,6 +97,9 @@
- [X] GRDB7: All writes should be immediate, right? https://github.com/groue/GRDB.swift/pull/1485#issuecomment-1953793553
- [X] GRDB7: Remove concurrenRead and DatabaseFuture
- [ ] GRDB7: Sendable conformances
- [ ] SerializedDatabase Sendable async closure
- [X] OnDemandFuture Sendable async closure
- [ ] WALSnapshotTransaction refactor
- [X] anydatabasecancellable
- [ ] anydatabaseregionconvertible
- [ ] anyfetchrequest