https://kotlinlang.org logo
#redux
Title
n

Nikky

02/06/2020, 9:07 PM
i have no idea how i did not run into this before..
java.lang.IllegalStateException: You may not call the store from a thread other than the thread on which it was created.
but how would be the easiest way to lets say.. make sure that this does not happen by using the same thread / coroutine context ?
c

Chenn

02/18/2020, 10:22 AM
I'm uncertain, but it sounds like you're trying to alter the state in a coroutine. If you want to use redux with suspending functions I recommend using architectures like redux-saga. This architecture allows for suspending functions to trigger actions in the main thread.
p

Patrick Jackson

02/18/2020, 2:11 PM
all calls to
store,dispatch
and
store.state
need to happen on the same thread. You may be accessing store.state from another thread?
One way to due this is always use a coroutineScope with the main dispatcher -
CoroutineScope(Dispatchers.Main)
the 'same thread enforcement' will probably change in new versions. I'm waiting for kotlin 1.3.7 to finalize and the approach may change. If you run into problems, previous versions of ReduxKotlin do not have the same thread enforcement
n

Nikky

02/24/2020, 9:22 AM
i ended up creating newSingleThread something for each store (i have one each for different concurrently running processes as well as one for managing references to them) but a coroutine compatible approach that does threadswitching for me would be nice
t

tim

03/10/2020, 3:59 PM
Running into this now. Trying write an integration test that queries an endpoint which gets the state from a store ... going to try and wrap dispatch and getState
👍 1
p

Patrick Jackson

03/17/2020, 1:38 PM
Looks like I'll have some time soon to update redux-kotlin with the shelter in place for the forseeable future. Please log a detailed issue ticket if you run into bugs or recommendations/feature requests
t

tim

03/17/2020, 1:39 PM
👍
Wrapping dispatch / getState solved it for me
2 Views