     }
 
     private func defaultDispatch(action: Action) {
-        guard !isDispatching else {
+        guard dispatchingLock.try() else {
             raiseFatalError("ReSwift:IllegalDispatchFromReducer - Reducers may not dispatch actions.")
         }
-
-        isDispatching = true
         observable.value = reducer.run(action: action, state: observable.value)
-        isDispatching = false
+        dispatchingLock.unlock()
     }
 
     @discardableResult


    public var observable: ObservableProperty!

    private var isDispatching = false

    private var disposeBag = SubscriptionReferenceBag()


 contained within an observable.
 */

import Foundation

public class Store<ObservableProperty: ObservablePropertyType>: StoreType where ObservableProperty.ValueType: StateType {

    public typealias StoreMiddleware = Middleware<ObservableProperty.ValueType>
