Skip to content

Commit

Permalink
bug fix: in AsyncReduksActivity: subscriber and reducer coroutine con…
Browse files Browse the repository at this point in the history
…text where swapped
  • Loading branch information
beyondeye authored and daely committed Jan 1, 2018
1 parent ae95b68 commit 3e9e4cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.beyondeye.reduks.*
import com.beyondeye.reduks.experimental.AsyncStore
import com.beyondeye.reduksAndroid.activity.ActionRestoreState
import com.beyondeye.reduksAndroid.activity.ReduksActivity
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.android.UI

/**
Expand All @@ -21,7 +22,7 @@ abstract class AsyncReduksActivity<S>: ReduksActivity<S>, AppCompatActivity() {
reduks=initReduks()
}

override fun <T> storeCreator(): StoreCreator<T> = AsyncStore.Creator<T>(subscribeContext = UI)
override fun <T> storeCreator(): StoreCreator<T> = AsyncStore.Creator<T>(reduceContext = CommonPool,subscribeContext = UI)

//override for making this function visible to inheritors
override fun onStop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AsyncStore<S>(initialState: S, private var reducer: Reducer<S>,
val reduceContext: CoroutineContext =DefaultDispatcher,
val withStandardMiddleware:Boolean=true) : StoreCreator<S> {
override fun create(reducer: Reducer<S>, initialState: S): Store<S> {
val res = AsyncStore<S>(initialState, reducer,reduceContext,subscribeContext)
val res = AsyncStore<S>(initialState, reducer,subscribeContext,reduceContext)
return if (!withStandardMiddleware)
res
else
Expand All @@ -48,7 +48,7 @@ class AsyncStore<S>(initialState: S, private var reducer: Reducer<S>,
}
//NOTE THAT IF THE ObserveContext is a single thread(the ui thread)
// then subscribers will be notified sequentially of state changes in the correct
private fun startSubscriberNotifierActor(c: CoroutineContext = DefaultDispatcher) = actor<S>(c) {
private fun startSubscriberNotifierActor(c: CoroutineContext) = actor<S>(c) {
for(updatedState in channel) { //iterate over incoming state updates
notifySubscribers()
}
Expand Down

0 comments on commit 3e9e4cd

Please sign in to comment.