Skip to content

Code that reproduces a race condition in CoRedux Side Effects

Notifications You must be signed in to change notification settings

mosofsky/CoReduxSideEffectRaceCondition

Repository files navigation

CoReduxSideEffectRaceCondition

This repository is meant to solve Race condition for side effects in CoRedux Side Effects

As of this commit, the race condition has been resolved by implementing SideEffect rather than instantiating SimpleSideEffect.

Only use SimpleSideEffect and CancellableSideEffect when you want to cancel the side effect if a new action of the same type comes in too quickly.

To see the original problem, go back to commit a7f7b155 ("Simplified test"). To see other solutions attempted, look at other branches such as feature/solve-by-using-multiple-actions.

Steps to demonstrate solution

You can demonstrate the solution manually or automatically using the automated test in the repository.

Manual reproduction

  1. Launch app in emulator
  2. Leave "Add Delay" unchecked
  3. Click "Do Async Task"
  4. The output should read "[init, go, go, done, done]"

The original problem could be worked around by introducing a delay between the two events which resulted in the following behavior:

  1. Launch app in emulator
  2. Check "Add Delay"
  3. Click "Do Async Task"
  4. The output should read "[init, go, done, go, done]"

Automated reproduction

The two test cases above are automated as Espresso tests. To observe their behavior, run as follows:

  1. Open MainActivityTest in Android Studio
  2. Click the green run button in the gutter to run the two tests
  3. shouldDoTwoAsyncTasksWithoutDelay passes
  4. shouldDoTwoAsyncTasksWithDelay passes

About

Code that reproduces a race condition in CoRedux Side Effects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages