Skip to content

Commit 91e0231

Browse files
authored
Merge pull request #20 from 0xOpenBytes/task-cancel
Support Task cancellation
2 parents 01694ce + c5f828e commit 91e0231

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Sources/CacheStore/Stores/Store/Store.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,14 @@ extension Store {
274274
let actionEffect = actionHandler.handle(store: &cacheStoreCopy, action: action, dependency: dependency)
275275

276276
if let actionEffect = actionEffect {
277-
if let runningEffect = effects[actionEffect.id] {
278-
runningEffect.cancel()
279-
}
280-
277+
cancel(id: actionEffect.id)
281278
effects[actionEffect.id] = Task {
279+
if Task.isCancelled { return }
280+
282281
guard let nextAction = await actionEffect.effect() else { return }
283282

283+
if Task.isCancelled { return }
284+
284285
handle(action: nextAction)
285286
}
286287
}

0 commit comments

Comments
 (0)