Skip to content

Commit

Permalink
[subscription-cancellation-fix] Cancel subscriptions on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
lailabecker committed Oct 3, 2023
1 parent 72a1fe4 commit 7f4309f
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public class MainThreadStore<State, Action>(private val delegate: TypedStore<Sta
override val store: Store<State> = 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 <T> runOnMainThread(block: () -> T): T =
Expand Down

0 comments on commit 7f4309f

Please sign in to comment.