i have no idea how i did not run into this before....
# redux
n
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
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
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
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
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
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
👍
Wrapping dispatch / getState solved it for me