Skip to content

Commit cf29124

Browse files
iampatbrownmluisbrown
authored andcommitted
Defer action removal until last (#1328)
(cherry picked from commit cfdb845e5707191f87d0e8c72180d4d46c4f4158)
1 parent c487fb3 commit cf29124

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Sources/ComposableArchitecture/Store.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,11 @@ public final class Store<State, Action> {
343343

344344
let tasks = Box<[Task<Void, Never>]>(wrappedValue: [])
345345

346-
while !self.bufferedActions.isEmpty {
347-
let action = self.bufferedActions.removeFirst()
346+
var index = self.bufferedActions.startIndex
347+
defer { self.bufferedActions = [] }
348+
while index < self.bufferedActions.endIndex {
349+
defer { index += 1 }
350+
let action = self.bufferedActions[index]
348351
let effect = self.reducer(&currentState, action)
349352

350353
switch effect.operation {

0 commit comments

Comments
 (0)