From c5f828ec2bdfc2fe8cc210fb9f7bc7d743147993 Mon Sep 17 00:00:00 2001 From: Leif Date: Thu, 21 Jul 2022 17:19:56 -0600 Subject: [PATCH] Support Task cancellation --- Sources/CacheStore/Stores/Store/Store.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/CacheStore/Stores/Store/Store.swift b/Sources/CacheStore/Stores/Store/Store.swift index 03106aa..b29ac94 100644 --- a/Sources/CacheStore/Stores/Store/Store.swift +++ b/Sources/CacheStore/Stores/Store/Store.swift @@ -274,13 +274,14 @@ extension Store { let actionEffect = actionHandler.handle(store: &cacheStoreCopy, action: action, dependency: dependency) if let actionEffect = actionEffect { - if let runningEffect = effects[actionEffect.id] { - runningEffect.cancel() - } - + cancel(id: actionEffect.id) effects[actionEffect.id] = Task { + if Task.isCancelled { return } + guard let nextAction = await actionEffect.effect() else { return } + if Task.isCancelled { return } + handle(action: nextAction) } }