reduxkotlin / redux-kotlin

Redux implementation for Kotlin (supports multiplatform JVM, native, JS, WASM)
https://reduxkotlin.org
MIT License
426 stars 32 forks source link

Thread confined dispatch? #12

Closed AOrobator closed 4 years ago

AOrobator commented 5 years ago

Should calls to Store.dispatch be thread confined? Particularly to the main/ui thread of the platform? Dealing with multi-threaded updates to State can get hairy

patjackson52 commented 5 years ago

Yes, calls to dispatch should be thread confined. In particular, the reducers need to be executed on the same thread. In my experience the main thread has been used and have not ran into any problems, but an optimal solution may be to do all middleware/reducers off the mainthread, and only updated the UI when subscibers are called.

Yes, enforcing a single/same thread within the library would be good to prevent race conditions. This could be done inside of the dispatch function in createStore