Skip to content

Commit bd3c3bb

Browse files
committed
fix trigger firing multiple times
fixes a bug that occurred when the attached view gets destroyed before the action was completed and thus the state was not reset. When the view was recreated, the task would trigger again leading to unexpected behavior. Now the task trigger will always reset.
1 parent 0653d6f commit bd3c3bb

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Sources/TaskTrigger/TaskTriggerViewModifier.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ struct TaskTriggerViewModifier<Value: Equatable>: ViewModifier where Value: Send
3232
return
3333
}
3434

35+
// reset the trigger's state to none to allow re-triggering in the future.
36+
defer { trigger.cancel() }
37+
3538
// execute the async work.
3639
await action(value)
37-
38-
// if not already cancelled, reset the trigger.
39-
if !Task.isCancelled {
40-
self.trigger.cancel()
41-
}
4240
}
4341
}
4442
}

0 commit comments

Comments
 (0)