mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-22 04:00:39 +00:00
OnDemandFuture fulfill is Sendable
This commit is contained in:
1 parent
f13b2d2eb4
commit
2aabc4c10e
3 files changed
+13
-8
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user