File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Sources/ComposableArchitecture/Documentation.docc/Articles Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1020,6 +1020,28 @@ problems due to re-entrancy. To avoid problems like the above we recommend wrapp
10201020mutations of the shared state as possible in a single ``Shared/ withLock (_:)``. That will make
10211021sure that the full unit of work is guarded by a lock.
10221022
1023+ > Note: You may encounter a deprecation warning when simply _accessing_ shared state from an
1024+ > asynchronous context when you chain into a subscript :
1025+ >
1026+ > ```swift
1027+ > return .run { _ in
1028+ > @Shared (.posts ) var posts
1029+ > let post = posts[id : id] // ⚠️ Setter is unavailable from asynchronous contexts
1030+ > // ...
1031+ > }
1032+ > ```
1033+ >
1034+ > This is a [known issue](https :// github.com/apple/swift/issues/74203) in the Swift compiler, but
1035+ > can be worked around using ``Shared/ withLock (_:)`` to access the underlying value instead:
1036+ >
1037+ > ```swift
1038+ > return .run { _ in
1039+ > @Shared (.posts ) var posts
1040+ > let post = $posts.withLock { $0 [id : id] }
1041+ > // ...
1042+ > }
1043+ > ```
1044+
10231045## Gotchas of @Shared
10241046
10251047There are a few gotchas to be aware of when using shared state in the Composable Architecture.
You can’t perform that action at this time.
0 commit comments