reduxkotlin / redux-kotlin

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

issue #38bugfix issue #38 enforce same thread #39

Closed patjackson52 closed 4 years ago

patjackson52 commented 4 years ago

38 incorrectly throwing exception when interacting on same thread.

Appears coroutines appends "@coroutine#n" to the thread name, and this can change when suspending/resuming coroutines. The solution provided in this PR strips the coroutine name from the threadname. A test that fails without stripping the suffix has been added in ThreadUtilSpec.

Long term, handling of same thread enforcement may change - perhaps wrapping store in channel or actor. For now this should work, however all interactions with the store will need to be from a singleThreadCoroutine context, such as one with Dispatchers.Main or for native - https://github.com/reduxkotlin/ReadingListSampleApp/blob/master/common/src/iosMain/kotlin/org/reduxkotlin/readinglist/common/UI.kt @jennymolske