         let deferred = Deferred<V>(promise: self)
         deferred.resolve(vagueThenable: vagueThenable)
     }
-    /*
-    func resolve<T: Thenable where T.ValueType == V, T.ReasonType == Optional<Any>, T.ReturnType == Optional<Any>>(#vagueThenable: T) -> Void
-    {
-        if self.state != .Pending {
-            return
-        }
-        
-        vagueThenable.then(
-            onFulfilled: { (value: V) -> Any? in
-                self.resolve(value)
-                return nil
-            },
-            onRejected: { (reason: Any?) -> Any? in
-                if let reasonObject = reason as? NSError {
-                    self.reject(reasonObject)
-                }
-                else {
-                    self.reject(NSError.promiseReasonWrapperError(reason))
-                }
-                return nil
-            }
-        )
-    }
-*/
 }
    {
        return self.race(promises)
    }
    
    // MARK: - Thenable
    
    public typealias NextType = Promise<Void>
    public typealias ValueType = V
    public typealias ReasonType = NSError
    public typealias ReturnType = Void
    
    public func then(
        onFulfilled: Optional<(value: V) -> Void> = nil,
        onRejected: Optional<(reason: NSError) -> Void> = nil
        ) -> Promise<Void>
    {
        let (nextDeferred, nextPromise) = Promise<Void>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                if let resolution = onFulfilled? {
                    resolution(value: value)
                    nextDeferred.resolve()
                }
                else {
                    nextDeferred.resolve()
                }
            },
            rejectCallback: { (reason) -> Void in
                if let rejection = onRejected? {
                    rejection(reason: reason)
                    nextDeferred.resolve()
                }
                else {
                    nextDeferred.reject(reason)
                }
            }
        )
        
        return nextPromise
    }

    // MARK: - Thenable enhance
    
    public func then(
        onFulfilled: (value: V) -> Void
        ) -> Promise<Void>
    {
        let (nextDeferred, nextPromise) = Promise<Void>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                onFulfilled(value: value)
                nextDeferred.resolve()
            },
            rejectCallback: { (reason) -> Void in
                nextDeferred.reject(reason)
            }
        )
        
        return nextPromise
    }
    
    public func catch(
        onRejected: (reason: NSError) -> Void
        ) -> Promise<Void>
    {
        let (nextDeferred, nextPromise) = Promise<Void>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                nextDeferred.resolve()
            },
            rejectCallback: { (reason) -> Void in
                onRejected(reason: reason)
                nextDeferred.resolve()
            }
        )

        return nextPromise
    }
    
    public func then<N: Any>(
        #onFulfilled: (value: V) -> N,
        onRejected: (reason: NSError) -> N
        ) -> Promise<N>
    {
        let (nextDeferred, nextPromise) = Promise<N>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                let nextValue = onFulfilled(value: value)
                nextDeferred.resolve(nextValue)
            },
            rejectCallback: { (reason) -> Void in
                let nextValue = onRejected(reason: reason)
                nextDeferred.resolve(nextValue)
            }
        )
        
        return nextPromise
    }
    
    public func then<N>(
        onFulfilled: (value: V) -> N
        ) -> Promise<N>
    {
        let (nextDeferred, nextPromise) = Promise<N>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                let nextValue = onFulfilled(value: value)
                nextDeferred.resolve(nextValue)
            },
            rejectCallback: { (reason) -> Void in
                nextDeferred.reject(reason)
            }
        )

        return nextPromise
    }

    public func then<N, T: Thenable where T.ValueType == N, T.ReasonType == NSError, T.ReturnType == Void>(
        #onFulfilled: (value: V) -> T,
        onRejected: (reason: NSError) -> T
        ) -> Promise<N>
    {
        let (nextDeferred, nextPromise) = Promise<N>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                let nextThenable = onFulfilled(value: value)
                nextDeferred.resolve(thenable: nextThenable)
            },
            rejectCallback: { (reason) -> Void in
                let nextThenable = onRejected(reason: reason)
                nextDeferred.resolve(thenable: nextThenable)
            }
        )
        
        return nextPromise
    }
    
    public func then<N, T: Thenable where T.ValueType == N, T.ReasonType == NSError, T.ReturnType == Void>(
        onFulfilled: (value: V) -> T
        ) -> Promise<N>
    {
        let (nextDeferred, nextPromise) = Promise<N>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                let nextThenable = onFulfilled(value: value)
                nextDeferred.resolve(thenable: nextThenable)
            },
            rejectCallback: { (reason) -> Void in
                nextDeferred.reject(reason)
            }
        )
        
        return nextPromise
    }
}

public extension Promise {

            break
        }
    }

    // MARK: - Static APIs
    
    public class func defer() -> (Deferred<V>, Promise<V>) {
        let deferred = Deferred<V>()
        return (deferred, deferred.promise)
    }
    
    // MARK: - Thenable
    
    public typealias NextType = Promise<Void>
    public typealias ValueType = V
    public typealias ReasonType = NSError
    public typealias ReturnType = Void
    
    public func then(
        onFulfilled: Optional<(value: V) -> Void> = nil,
        onRejected: Optional<(reason: NSError) -> Void> = nil
        ) -> Promise<Void>
    {
        let (nextDeferred, nextPromise) = Promise<Void>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                if let resolution = onFulfilled? {
                    resolution(value: value)
                    nextDeferred.resolve()
                }
                else {
                    nextDeferred.resolve()
                }
            },
            rejectCallback: { (reason) -> Void in
                if let rejection = onRejected? {
                    rejection(reason: reason)
                    nextDeferred.resolve()
                }
                else {
                    nextDeferred.reject(reason)
                }
            }
        )
        
        return nextPromise
    }

    // MARK: - Thenable enhance
    
    public func then(
        onFulfilled: (value: V) -> Void
        ) -> Promise<Void>
    {
        let (nextDeferred, nextPromise) = Promise<Void>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                onFulfilled(value: value)
                nextDeferred.resolve()
            },
            rejectCallback: { (reason) -> Void in
                nextDeferred.reject(reason)
            }
        )
        
        return nextPromise
    }
    
    public func catch(
        onRejected: (reason: NSError) -> Void
        ) -> Promise<Void>
    {
        let (nextDeferred, nextPromise) = Promise<Void>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                nextDeferred.resolve()
            },
            rejectCallback: { (reason) -> Void in
                onRejected(reason: reason)
                nextDeferred.resolve()
            }
        )

        return nextPromise
    }
    
    public func then<N: Any>(
        #onFulfilled: (value: V) -> N,
        onRejected: (reason: NSError) -> N
        ) -> Promise<N>
    {
        let (nextDeferred, nextPromise) = Promise<N>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                let nextValue = onFulfilled(value: value)
                nextDeferred.resolve(nextValue)
            },
            rejectCallback: { (reason) -> Void in
                let nextValue = onRejected(reason: reason)
                nextDeferred.resolve(nextValue)
            }
        )
        
        return nextPromise
    }
    
    public func then<N>(
        onFulfilled: (value: V) -> N
        ) -> Promise<N>
    {
        let (nextDeferred, nextPromise) = Promise<N>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                let nextValue = onFulfilled(value: value)
                nextDeferred.resolve(nextValue)
            },
            rejectCallback: { (reason) -> Void in
                nextDeferred.reject(reason)
            }
        )

        return nextPromise
    }

    public func then<N, T: Thenable where T.ValueType == N, T.ReasonType == NSError, T.ReturnType == Void>(
        #onFulfilled: (value: V) -> T,
        onRejected: (reason: NSError) -> T
        ) -> Promise<N>
    {
        let (nextDeferred, nextPromise) = Promise<N>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                let nextThenable = onFulfilled(value: value)
                nextDeferred.resolve(thenable: nextThenable)
            },
            rejectCallback: { (reason) -> Void in
                let nextThenable = onRejected(reason: reason)
                nextDeferred.resolve(thenable: nextThenable)
            }
        )
        
        return nextPromise
    }
    
    public func then<N, T: Thenable where T.ValueType == N, T.ReasonType == NSError, T.ReturnType == Void>(
        onFulfilled: (value: V) -> T
        ) -> Promise<N>
    {
        let (nextDeferred, nextPromise) = Promise<N>.defer()
        
        self.bindCallbacks(
            fulfillCallback: { (value) -> Void in
                let nextThenable = onFulfilled(value: value)
                nextDeferred.resolve(thenable: nextThenable)
            },
            rejectCallback: { (reason) -> Void in
                nextDeferred.reject(reason)
            }
        )
        
        return nextPromise
    }
}

public extension Promise {
    
    public class func resolve<V>(value: Any) -> Promise<V>
    {
