Skip to content

Unsubscribing when using in a multi threaded way throws Exceptions #165

Open
@christopherperry

Description

@christopherperry

Hey team, I'm using a thread safe store via createTypedThreadSafeStore(). My code is roughly:

storeSubscription = store.subscribe {
    coroutineScope.launch { ui.update(store.state) }
}

actionFlow.onEach { action ->
  store.dispatch(action)
}.flowOn(Dispatchers.Default)
 .launchIn(coroutineScope)

Then in the shutdown part of the lifecycle I call on the main thread:

storeSubscription?.invoke()

and it sometimes throws the error

You may not unsubscribe from a store listener while the reducer
|is executing. See
|https://www.reduxkotlin.org/api/store#subscribelistener-storesubscriber
|for more details.

I noticed in your samples you don't unsubscribe. How do I use your library in a multi-threaded way and safely unsubscribe?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions