From 7f4309fb9d220bd51d9a5d558b719d4098223fb0 Mon Sep 17 00:00:00 2001 From: Laila Becker Date: Tue, 3 Oct 2023 16:50:28 +0200 Subject: [PATCH] [subscription-cancellation-fix] Cancel subscriptions on main thread --- .../dreipol/dreimultiplatform/reduxkotlin/MainThreadStore.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/ch/dreipol/dreimultiplatform/reduxkotlin/MainThreadStore.kt b/src/commonMain/kotlin/ch/dreipol/dreimultiplatform/reduxkotlin/MainThreadStore.kt index 41655bd..293c642 100644 --- a/src/commonMain/kotlin/ch/dreipol/dreimultiplatform/reduxkotlin/MainThreadStore.kt +++ b/src/commonMain/kotlin/ch/dreipol/dreimultiplatform/reduxkotlin/MainThreadStore.kt @@ -36,7 +36,9 @@ public class MainThreadStore(private val delegate: TypedStore = delegate.store override val subscribe: (StoreSubscriber) -> StoreSubscription = { subscriber -> - runOnMainThread { delegate.subscribe(subscriber) } + val subscription = runOnMainThread { delegate.subscribe(subscriber) } + val onMainThread = { runOnMainThread { subscription() } } + onMainThread } private fun runOnMainThread(block: () -> T): T =