 				case let .Unresolved(work):
 					self.state = .Resolving
 					return work
+					
 				case let .Done(result):
 					fallthrough
 				case .Resolving:

			
			withLock(self.condition) { () -> () in
				self.state = PromiseState.Done { result }
				self.condition.broadcast()
			}
		}
	}
	
	func result() -> T {
		let (maybeWork: (() -> T)?, maybeResult: T?) = withLock(self.condition) {
			while self.isResolving {
				self.condition.wait()
			}


	case Unresolved(() -> T)
	case Resolving
	case Done(() -> T)
	
	var isResolving: Bool {
		get {
			switch self {
			case .Resolving:
				return true
			default:
				return false
			}
		}
	}
}

class Promise<T> {
	let condition = NSCondition()
	var finishedActions: (() -> ())[] = []
	
	var state: PromiseState<T> {
		willSet(newState) {
			switch newState {
			case .Done:
				for action in self.finishedActions {
					action()
				}
				
				self.finishedActions = []
				self.condition.broadcast()
				
			default:
				break
			}
		}
	}
