 
   public func determine(value: T) throws
   {
-    super.setState(.Working)
+    super.setState(.Executing)
     try super.setValue(value)
   }
 
   public func beginWork()
   {
-    super.setState(.Working)
+    super.setState(.Executing)
   }
 }

    case .Waiting:
      return currentState == DeferredState.Waiting.rawValue

    case .Working:
      return OSAtomicCompareAndSwap32Barrier(DeferredState.Waiting.rawValue, DeferredState.Working.rawValue, &currentState)

    // case .Canceled:

    case .Assigning:
      return OSAtomicCompareAndSwap32Barrier(DeferredState.Working.rawValue, DeferredState.Assigning.rawValue, &currentState)

    case .Determined:
      if OSAtomicCompareAndSwap32Barrier(DeferredState.Assigning.rawValue, DeferredState.Determined.rawValue, &currentState)


import Dispatch

/**
  The states a Deferred can be in.

  Must be a top-level type because Deferred is generic.
*/

public enum DeferredState: Int32 { case Waiting = 0, Executing = 1, Determined = 3, Assigning = -1 }


public enum DeferredError: ErrorType { case AlreadyDetermined(String), CannotDetermine(String) }

/**
  An asynchronous computation.

  A `Deferred` starts out undetermined, in the `.Waiting` state. It may then enter the `.Executing` state,
  and will eventually become `.Determined`, and ready to supply a result.

  The `value` property will return the result, blocking until it becomes determined.
  If the result is ready when `value` is called, it will return immediately.
*/

