@@ -30,7 +30,7 @@ public final class RootStore {
30
30
31
31
self . isSending = true
32
32
var currentState = self . state as! State
33
- let tasks = Box < [ Task < Void , Never > ] > ( wrappedValue : [ ] )
33
+ let tasks = LockIsolated < [ Task < Void , Never > ] > ( [ ] )
34
34
defer {
35
35
withExtendedLifetime ( self . bufferedActions) {
36
36
self . bufferedActions. removeAll ( )
@@ -42,7 +42,7 @@ public final class RootStore {
42
42
self . bufferedActions. removeLast ( ) ,
43
43
originatingFrom: originatingAction
44
44
) {
45
- tasks. wrappedValue . append ( task)
45
+ tasks. withValue { $0 . append ( task) }
46
46
}
47
47
}
48
48
}
@@ -75,7 +75,7 @@ public final class RootStore {
75
75
if let task = continuation. yield ( {
76
76
self . send ( effectAction, originatingFrom: action)
77
77
} ) {
78
- tasks. wrappedValue . append ( task)
78
+ tasks. withValue { $0 . append ( task) }
79
79
}
80
80
}
81
81
)
@@ -87,63 +87,62 @@ public final class RootStore {
87
87
effectCancellable. cancel ( )
88
88
}
89
89
boxedTask. wrappedValue = task
90
- tasks. wrappedValue . append ( task)
90
+ tasks. withValue { $0 . append ( task) }
91
91
self . effectCancellables [ uuid] = effectCancellable
92
92
}
93
93
case let . run( priority, operation) :
94
94
withEscapedDependencies { continuation in
95
- tasks. wrappedValue. append (
96
- Task ( priority: priority) { @MainActor in
97
- let isCompleted = LockIsolated ( false )
98
- defer { isCompleted. setValue ( true ) }
99
- await operation (
100
- Send { effectAction in
101
- if isCompleted. value {
102
- reportIssue (
103
- """
104
- An action was sent from a completed effect:
95
+ let task = Task ( priority: priority) { @MainActor in
96
+ let isCompleted = LockIsolated ( false )
97
+ defer { isCompleted. setValue ( true ) }
98
+ await operation (
99
+ Send { effectAction in
100
+ if isCompleted. value {
101
+ reportIssue (
102
+ """
103
+ An action was sent from a completed effect:
105
104
106
- Action:
107
- \( debugCaseOutput ( effectAction) )
105
+ Action:
106
+ \( debugCaseOutput ( effectAction) )
108
107
109
- Effect returned from:
110
- \( debugCaseOutput ( action) )
108
+ Effect returned from:
109
+ \( debugCaseOutput ( action) )
111
110
112
- Avoid sending actions using the 'send' argument from 'Effect.run' after \
113
- the effect has completed. This can happen if you escape the 'send' \
114
- argument in an unstructured context.
111
+ Avoid sending actions using the 'send' argument from 'Effect.run' after \
112
+ the effect has completed. This can happen if you escape the 'send' \
113
+ argument in an unstructured context.
115
114
116
- To fix this, make sure that your 'run' closure does not return until \
117
- you're done calling 'send'.
118
- """
119
- )
120
- }
121
- if let task = continuation. yield ( {
122
- self . send ( effectAction, originatingFrom: action)
123
- } ) {
124
- tasks. wrappedValue. append ( task)
125
- }
115
+ To fix this, make sure that your 'run' closure does not return until \
116
+ you're done calling 'send'.
117
+ """
118
+ )
126
119
}
127
- )
128
- }
129
- )
120
+ if let task = continuation. yield ( {
121
+ self . send ( effectAction, originatingFrom: action)
122
+ } ) {
123
+ tasks. withValue { $0. append ( task) }
124
+ }
125
+ }
126
+ )
127
+ }
128
+ tasks. withValue { $0. append ( task) }
130
129
}
131
130
}
132
131
}
133
132
134
- guard !tasks. wrappedValue . isEmpty else { return nil }
133
+ guard !tasks. isEmpty else { return nil }
135
134
return Task { @MainActor in
136
135
await withTaskCancellationHandler {
137
- var index = tasks. wrappedValue . startIndex
138
- while index < tasks. wrappedValue . endIndex {
136
+ var index = tasks. startIndex
137
+ while index < tasks. endIndex {
139
138
defer { index += 1 }
140
- await tasks. wrappedValue [ index] . value
139
+ await tasks [ index] . value
141
140
}
142
141
} onCancel: {
143
- var index = tasks. wrappedValue . startIndex
144
- while index < tasks. wrappedValue . endIndex {
142
+ var index = tasks. startIndex
143
+ while index < tasks. endIndex {
145
144
defer { index += 1 }
146
- tasks. wrappedValue [ index] . cancel ( )
145
+ tasks [ index] . cancel ( )
147
146
}
148
147
}
149
148
}
0 commit comments