Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Add more strict concurrency information
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jul 7, 2024
1 parent e0c5808 commit 5a46898
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

/// Store a reference to a rendered view in a view storage.
public class RenderableStorage {
public actor RenderableStorage {

/// The pointer.
///
Expand Down
4 changes: 2 additions & 2 deletions Sources/View/AppearObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct AppearObserver: ConvenienceWidget {
/// - modifiers: Modify views before being updated.
/// - type: The type of the app storage.
func container<Storage>(
modifiers: [(any AnyView) -> any AnyView],
modifiers: [@Sendable (any AnyView) -> any AnyView],
type: Storage.Type
) -> ViewStorage where Storage: AppStorage {
let storage = content.storage(modifiers: modifiers, type: type)
Expand All @@ -34,7 +34,7 @@ struct AppearObserver: ConvenienceWidget {
/// - type: The type of the app storage.
func update<Storage>(
_ storage: ViewStorage,
modifiers: [(any AnyView) -> any AnyView],
modifiers: [@Sendable (any AnyView) -> any AnyView],
updateProperties: Bool,
type: Storage.Type
) where Storage: AppStorage {
Expand Down
6 changes: 3 additions & 3 deletions Sources/View/ContentModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ContentModifier<Content>: ConvenienceWidget where Content: AnyView {
/// - modifiers: Modify views before being updated.
/// - type: The type of the app storage.
func container<Storage>(
modifiers: [(any AnyView) -> any AnyView],
modifiers: [@Sendable (any AnyView) -> any AnyView],
type: Storage.Type
) -> ViewStorage where Storage: AppStorage {
content.storage(modifiers: modifiers + [modifyView], type: type)
Expand All @@ -32,7 +32,7 @@ struct ContentModifier<Content>: ConvenienceWidget where Content: AnyView {
/// - type: The type of the app storage.
func update<Storage>(
_ storage: ViewStorage,
modifiers: [(any AnyView) -> any AnyView],
modifiers: [@Sendable (any AnyView) -> any AnyView],
updateProperties: Bool,
type: Storage.Type
) where Storage: AppStorage {
Expand All @@ -42,7 +42,7 @@ struct ContentModifier<Content>: ConvenienceWidget where Content: AnyView {

/// Apply the modifier to a view.
/// - Parameter view: The view.
func modifyView(_ view: AnyView) -> AnyView {
@Sendable func modifyView(_ view: AnyView) -> AnyView {
if let view = view as? Content {
return modify(view).stopModifiers()
} else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/View/Freeze.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Freeze: ConvenienceWidget {
/// - modifiers: Modify views before being updated.
/// - type: The type of the app storage.
func container<Storage>(
modifiers: [(any AnyView) -> any AnyView],
modifiers: [@Sendable (any AnyView) -> any AnyView],
type: Storage.Type
) -> ViewStorage where Storage: AppStorage {
content.storage(modifiers: modifiers, type: type)
Expand All @@ -32,7 +32,7 @@ struct Freeze: ConvenienceWidget {
/// - type: The type of the app storage.
func update<Storage>(
_ storage: ViewStorage,
modifiers: [(any AnyView) -> any AnyView],
modifiers: [@Sendable (any AnyView) -> any AnyView],
updateProperties: Bool,
type: Storage.Type
) where Storage: AppStorage {
Expand Down
4 changes: 2 additions & 2 deletions Sources/View/InspectorWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct InspectorWrapper: ConvenienceWidget {
/// - modifiers: Modify views before being updated.
/// - type: The type of the app storage.
func container<Storage>(
modifiers: [(any AnyView) -> any AnyView],
modifiers: [@Sendable (any AnyView) -> any AnyView],
type: Storage.Type
) -> ViewStorage where Storage: AppStorage {
let storage = content.storage(modifiers: modifiers, type: type)
Expand All @@ -34,7 +34,7 @@ struct InspectorWrapper: ConvenienceWidget {
/// - type: The type of the app storage.
func update<Storage>(
_ storage: ViewStorage,
modifiers: [(any AnyView) -> any AnyView],
modifiers: [@Sendable (any AnyView) -> any AnyView],
updateProperties: Bool,
type: Storage.Type
) where Storage: AppStorage {
Expand Down
4 changes: 2 additions & 2 deletions Sources/View/ModifierStopper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct ModifierStopper: ConvenienceWidget {
/// - modifiers: Modify views before being updated.
/// - type: The type of the app storage.
func container<Storage>(
modifiers: [(any AnyView) -> any AnyView],
modifiers: [@Sendable (any AnyView) -> any AnyView],
type: Storage.Type
) -> ViewStorage where Storage: AppStorage {
content.storage(modifiers: [], type: type)
Expand All @@ -30,7 +30,7 @@ struct ModifierStopper: ConvenienceWidget {
/// - type: The type of the app storage.
func update<Storage>(
_ storage: ViewStorage,
modifiers: [(any AnyView) -> any AnyView],
modifiers: [@Sendable (any AnyView) -> any AnyView],
updateProperties: Bool,
type: Storage.Type
) where Storage: AppStorage {
Expand Down
12 changes: 6 additions & 6 deletions Tests/SampleBackends/Backend1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public enum Backend1 {
self.action = action
}

public func container<Storage>(modifiers: [(any AnyView) -> any AnyView], type: Storage.Type) -> ViewStorage where Storage: AppStorage {
public func container<Storage>(modifiers: [@Sendable (any AnyView) -> any AnyView], type: Storage.Type) -> ViewStorage where Storage: AppStorage {
print("Init button")
let storage = ViewStorage(nil)
Task {
Expand All @@ -67,7 +67,7 @@ public enum Backend1 {
return storage
}

public func update<Storage>(_ storage: ViewStorage, modifiers: [(any AnyView) -> any AnyView], updateProperties: Bool, type: Storage.Type) {
public func update<Storage>(_ storage: ViewStorage, modifiers: [@Sendable (any AnyView) -> any AnyView], updateProperties: Bool, type: Storage.Type) {
Task {
if updateProperties {
print("Update button (label = \(label))")
Expand Down Expand Up @@ -98,15 +98,15 @@ public enum Backend1 {
print("Update renderable")
}

public func container<Storage>(modifiers: [(any AnyView) -> any AnyView], type: Storage.Type) -> ViewStorage where Storage: AppStorage {
public func container<Storage>(modifiers: [@Sendable (any AnyView) -> any AnyView], type: Storage.Type) -> ViewStorage where Storage: AppStorage {
let storage = ViewStorage(nil)
Task {
await storage.setRenderableContent(key: .mainContent, value: (content as [Renderable]).storages(type: MenuElement.self, fields: [:]))
}
return storage
}

public func update<Storage>(_ storage: ViewStorage, modifiers: [(any AnyView) -> any AnyView], updateProperties: Bool, type: Storage.Type) {
public func update<Storage>(_ storage: ViewStorage, modifiers: [@Sendable (any AnyView) -> any AnyView], updateProperties: Bool, type: Storage.Type) {
Task {
(content as [Renderable]).update(await storage.getRenderableContent(key: .mainContent), updateProperties: updateProperties, type: MenuElement.self, fields: [:])
}
Expand Down Expand Up @@ -158,15 +158,15 @@ public enum Backend1 {
self.content = content()
}

public func container<Storage>(modifiers: [(any Meta.AnyView) -> any Meta.AnyView], type: Storage.Type) -> Meta.ViewStorage where Storage : Meta.AppStorage {
public func container<Storage>(modifiers: [@Sendable (any Meta.AnyView) -> any Meta.AnyView], type: Storage.Type) -> Meta.ViewStorage where Storage : Meta.AppStorage {
let storage = ViewStorage(nil)
Task {
await storage.setContent(key: .mainContent, value: content.storages(modifiers: modifiers, type: type))
}
return storage
}

public func update<Storage>(_ storage: Meta.ViewStorage, modifiers: [(any Meta.AnyView) -> any Meta.AnyView], updateProperties: Bool, type: Storage.Type) where Storage : Meta.AppStorage {
public func update<Storage>(_ storage: Meta.ViewStorage, modifiers: [@Sendable (any Meta.AnyView) -> any Meta.AnyView], updateProperties: Bool, type: Storage.Type) where Storage : Meta.AppStorage {
Task {
content.update(await storage.getContent(key: .mainContent), modifiers: modifiers, updateProperties: updateProperties, type: type)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/SampleBackends/Backend2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public enum Backend2 {
self.content = content()
}

public func container<Storage>(modifiers: [(any Meta.AnyView) -> any Meta.AnyView], type: Storage.Type) -> Meta.ViewStorage where Storage : Meta.AppStorage {
public func container<Storage>(modifiers: [@Sendable (any Meta.AnyView) -> any Meta.AnyView], type: Storage.Type) -> Meta.ViewStorage where Storage : Meta.AppStorage {
let storage = ViewStorage(nil)
Task {
await storage.setContent(key: .mainContent, value: content.storages(modifiers: modifiers, type: type))
}
return storage
}

public func update<Storage>(_ storage: Meta.ViewStorage, modifiers: [(any Meta.AnyView) -> any Meta.AnyView], updateProperties: Bool, type: Storage.Type) where Storage : Meta.AppStorage {
public func update<Storage>(_ storage: Meta.ViewStorage, modifiers: [@Sendable (any Meta.AnyView) -> any Meta.AnyView], updateProperties: Bool, type: Storage.Type) where Storage : Meta.AppStorage {
Task {
content.update(await storage.getContent(key: .mainContent), modifiers: modifiers, updateProperties: updateProperties, type: type)
}
Expand Down

0 comments on commit 5a46898

Please sign in to comment.