From d0800858b9685524773d80c30dcde90effad9826 Mon Sep 17 00:00:00 2001 From: Muukii Date: Wed, 18 Sep 2024 22:59:08 +0900 Subject: [PATCH] Update --- Sources/Verge/Store/DetachedDispatcher.swift | 4 +-- Sources/Verge/Store/Scan.swift | 4 +-- Sources/Verge/Store/Store.swift | 8 +++--- Sources/Verge/Store/StoreDriverType.swift | 28 +++++++++++--------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Sources/Verge/Store/DetachedDispatcher.swift b/Sources/Verge/Store/DetachedDispatcher.swift index 598497486b..ff5a18e4a1 100644 --- a/Sources/Verge/Store/DetachedDispatcher.swift +++ b/Sources/Verge/Store/DetachedDispatcher.swift @@ -23,11 +23,11 @@ public final class DetachedDispatcher - public let scope: WritableKeyPath + public let scope: WritableKeyPath & Sendable init( store: Store, - scope: WritableKeyPath + scope: WritableKeyPath & Sendable ) { self.store = store self.scope = scope diff --git a/Sources/Verge/Store/Scan.swift b/Sources/Verge/Store/Scan.swift index c44e918762..95a504a9fa 100644 --- a/Sources/Verge/Store/Scan.swift +++ b/Sources/Verge/Store/Scan.swift @@ -21,9 +21,9 @@ import Foundation -public final class Scan { +public final class Scan: Sendable { - public typealias Accumulator = (inout Accumulate, Element) -> Void + public typealias Accumulator = @Sendable (inout Accumulate, Element) -> Void public var value: Accumulate { _value.value diff --git a/Sources/Verge/Store/Store.swift b/Sources/Verge/Store/Store.swift index bc5a17133e..b074053420 100644 --- a/Sources/Verge/Store/Store.swift +++ b/Sources/Verge/Store/Store.swift @@ -91,9 +91,9 @@ actor Writer { /// ``` /// You may use also `StoreWrapperType` to define State and Activity as inner types. /// -open class Store: EventEmitter<_StoreEvent>, CustomReflectable, StoreType, StoreDriverType, DerivedMaking, @unchecked Sendable { +open class Store: EventEmitter<_StoreEvent>, CustomReflectable, StoreType, StoreDriverType, DerivedMaking, @unchecked Sendable { - public var scope: WritableKeyPath = \State.self + public var scope: WritableKeyPath & Sendable = \State.self private let tracker = VergeConcurrency.SynchronizationTracker() @@ -772,7 +772,7 @@ Latest Version (%d): (%@) scan: Scan, Accumulate>, dropsFirst: Bool = false, queue: some TargetQueueType, - receive: @escaping (Changes, Accumulate) -> Void + receive: @escaping @Sendable (Changes, Accumulate) -> Void ) -> StoreStateSubscription { _primitive_sinkState(dropsFirst: dropsFirst, queue: queue) { (changes) in @@ -784,7 +784,7 @@ Latest Version (%d): (%@) } func _mainActor_sinkActivity( - queue: MainActorTargetQueue, + queue: some MainActorTargetQueueType, receive: @escaping @MainActor (sending Activity) -> Void ) -> StoreActivitySubscription { return _primitive_sinkActivity( diff --git a/Sources/Verge/Store/StoreDriverType.swift b/Sources/Verge/Store/StoreDriverType.swift index 167ab23b4c..3fc03c0355 100644 --- a/Sources/Verge/Store/StoreDriverType.swift +++ b/Sources/Verge/Store/StoreDriverType.swift @@ -51,16 +51,15 @@ public protocol StoreDriverType: ObservableObject where Activity == Targe associatedtype TargetStore: StoreType - associatedtype Scope: Equatable = TargetStore.State var store: TargetStore { get } - var scope: WritableKeyPath { get } + var scope: WritableKeyPath & Sendable { get } var state: Changes { get } // WORKAROUND: for activityPublisher() - associatedtype Activity = TargetStore.Activity + associatedtype Activity: Sendable = TargetStore.Activity } extension StoreDriverType { @@ -141,9 +140,14 @@ extension StoreDriverType where Scope == TargetStore.State { scan: Scan, Accumulate>, dropsFirst: Bool = false, queue: some TargetQueueType, - receive: @escaping (Changes, Accumulate) -> Void + receive: @escaping @Sendable (Changes, Accumulate) -> Void ) -> StoreStateSubscription { - store.asStore()._primitive_scan_sinkState(scan: scan, dropsFirst: dropsFirst, queue: queue, receive: receive) + store.asStore()._primitive_scan_sinkState( + scan: scan, + dropsFirst: dropsFirst, + queue: queue, + receive: receive + ) } /// Subscribe the state changes @@ -171,7 +175,7 @@ extension StoreDriverType where Scope == TargetStore.State { @_disfavoredOverload public func sinkActivity( queue: some TargetQueueType, - receive: @escaping (TargetStore.Activity) -> Void + receive: @escaping @Sendable (sending TargetStore.Activity) -> Void ) -> StoreActivitySubscription { store.asStore()._primitive_sinkActivity(queue: queue, receive: receive) @@ -183,11 +187,11 @@ extension StoreDriverType where Scope == TargetStore.State { /// - Returns: A subscriber that performs the provided closure upon receiving values. public func sinkActivity( queue: some MainActorTargetQueueType = .mainIsolated(), - receive: @escaping @MainActor (TargetStore.Activity) -> Void + receive: @escaping @MainActor (sending TargetStore.Activity) -> Void ) -> StoreActivitySubscription { store.asStore()._mainActor_sinkActivity(queue: queue) { activity in - thunkToMainActor { + MainActor.assumeIsolated { receive(activity) } } @@ -225,7 +229,7 @@ extension StoreDriverType { public func sinkState( dropsFirst: Bool = false, queue: some TargetQueueType, - receive: @escaping (Changes) -> Void + receive: @escaping @Sendable (Changes) -> Void ) -> StoreStateSubscription { let _scope = scope @@ -271,7 +275,7 @@ extension StoreDriverType { scan: Scan, Accumulate>, dropsFirst: Bool = false, queue: some TargetQueueType, - receive: @escaping (Changes, Accumulate) -> Void + receive: @escaping @Sendable (Changes, Accumulate) -> Void ) -> StoreStateSubscription { sinkState(dropsFirst: dropsFirst, queue: queue) { (changes) in let accumulate = scan.accumulate(changes) @@ -514,12 +518,12 @@ extension StoreDriverType { return result } - public func detached(from newScope: WritableKeyPath) + public func detached(from newScope: WritableKeyPath & Sendable) -> DetachedDispatcher { .init(store: store.asStore(), scope: newScope) } - public func detached(by appendingScope: WritableKeyPath) + public func detached(by appendingScope: WritableKeyPath & Sendable) -> DetachedDispatcher { .init(store: store.asStore(), scope: scope.appending(path: appendingScope)) }