mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-09-10 20:01:57 +02:00
Initial prototype for Swift 6 mode
This commit is contained in:
@@ -46,7 +46,7 @@ extension DataStack {
|
||||
/**
|
||||
Swift concurrency for the `DataStack` are exposed through this namespace. Extend this type if you need to add other `async` utilities for `DataStack`.
|
||||
*/
|
||||
public struct AsyncNamespace {
|
||||
public struct AsyncNamespace: Sendable {
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@@ -123,8 +123,8 @@ extension DataStack.AsyncNamespace {
|
||||
return .init(
|
||||
bufferingPolicy: .unbounded,
|
||||
{ continuation in
|
||||
|
||||
var progress: Progress? = nil
|
||||
|
||||
nonisolated(unsafe) var progress: Progress? = nil
|
||||
progress = self.base.addStorage(
|
||||
storage,
|
||||
completion: { result in
|
||||
@@ -151,14 +151,17 @@ extension DataStack.AsyncNamespace {
|
||||
)
|
||||
if let progress = progress {
|
||||
|
||||
progress.setProgressHandler { progress in
|
||||
Internals.mainActorImmediate { @MainActor in
|
||||
|
||||
progress.setProgressHandler { progress in
|
||||
|
||||
continuation.yield(
|
||||
.migrating(
|
||||
storage: storage,
|
||||
progressObject: progress
|
||||
continuation.yield(
|
||||
.migrating(
|
||||
storage: storage,
|
||||
progressObject: progress
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,7 +188,7 @@ extension DataStack.AsyncNamespace {
|
||||
|
||||
return try await Internals.withCheckedThrowingContinuation { continuation in
|
||||
|
||||
self.base.perform(
|
||||
return self.base.perform(
|
||||
asynchronous: { (transaction) -> O? in
|
||||
|
||||
return try transaction.importObject(
|
||||
@@ -196,10 +199,13 @@ extension DataStack.AsyncNamespace {
|
||||
success: {
|
||||
|
||||
continuation.resume(
|
||||
with: .success($0.flatMap(self.base.fetchExisting))
|
||||
returning: $0.flatMap(self.base.fetchExisting)
|
||||
)
|
||||
},
|
||||
failure: continuation.resume(throwing:)
|
||||
failure: {
|
||||
|
||||
continuation.resume(throwing: $0)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -222,6 +228,7 @@ extension DataStack.AsyncNamespace {
|
||||
source: O.ImportSource
|
||||
) async throws(any Swift.Error) -> O? {
|
||||
|
||||
nonisolated(unsafe) let object = object
|
||||
return try await Internals.withCheckedThrowingContinuation { continuation in
|
||||
|
||||
self.base.perform(
|
||||
@@ -240,10 +247,13 @@ extension DataStack.AsyncNamespace {
|
||||
success: {
|
||||
|
||||
continuation.resume(
|
||||
with: .success($0.flatMap(self.base.fetchExisting))
|
||||
returning: $0.flatMap(self.base.fetchExisting)
|
||||
)
|
||||
},
|
||||
failure: continuation.resume(throwing:)
|
||||
failure: {
|
||||
|
||||
continuation.resume(throwing: $0)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -279,10 +289,13 @@ extension DataStack.AsyncNamespace {
|
||||
success: {
|
||||
|
||||
continuation.resume(
|
||||
with: .success($0.flatMap(self.base.fetchExisting))
|
||||
returning: $0.flatMap(self.base.fetchExisting)
|
||||
)
|
||||
},
|
||||
failure: continuation.resume(throwing:)
|
||||
failure: {
|
||||
|
||||
continuation.resume(throwing: $0)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -306,7 +319,7 @@ extension DataStack.AsyncNamespace {
|
||||
- returns: The imported objects correctly associated for the `DataStack`.
|
||||
- throws: A `CoreStoreError` value indicating the failure reason
|
||||
*/
|
||||
public func importUniqueObjects<O: DynamicObject & ImportableUniqueObject, S: Sequence>(
|
||||
public func importUniqueObjects<O: DynamicObject & ImportableUniqueObject, S: Sequence & Sendable>(
|
||||
_ into: Into<O>,
|
||||
sourceArray: S,
|
||||
preProcess: @escaping @Sendable (
|
||||
@@ -329,10 +342,13 @@ extension DataStack.AsyncNamespace {
|
||||
success: {
|
||||
|
||||
continuation.resume(
|
||||
with: .success(self.base.fetchExisting($0))
|
||||
returning: self.base.fetchExisting($0)
|
||||
)
|
||||
},
|
||||
failure: continuation.resume(throwing:)
|
||||
failure: {
|
||||
|
||||
continuation.resume(throwing: $0)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -357,7 +373,7 @@ extension DataStack.AsyncNamespace {
|
||||
- returns: The value returned from the `task` closure.
|
||||
- throws: A `CoreStoreError` value indicating the failure reason
|
||||
*/
|
||||
public func perform<Output>(
|
||||
public func perform<Output: Sendable>(
|
||||
_ asynchronous: @escaping @Sendable (AsynchronousDataTransaction) throws(any Swift.Error) -> Output
|
||||
) async throws(any Swift.Error) -> Output {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user