             
         default:
             fatalError("Duplicate attempt to resolve promise")
-        }
-    }
-    
-    private func weakifyReject() -> (Error) -> Void {
-        return { [weak self] (reason) in
-            guard let strongSelf = self else { return }
-            
-            strongSelf.reject(reason)
         }
     }
     

            return self == nil
        }
        
        promise(weakifyFulfill(), weakifyReject(), isCancelled)
    }
    
    public func then<ResultingValue>(on dispatcher: Dispatcher, onFulfilled: @escaping (Value) throws -> Fulfilled<ResultingValue>, onRejected: @escaping (Error) throws -> Fulfilled<ResultingValue>) -> Promise<ResultingValue> {
        return Promise<ResultingValue>(pendingPromise: self) { (resolve, reject) in
            self.onResolve(

        case .pending(let deferred):
            state = .pending(Deferred(pendingPromise: promise, onFulfilled: deferred.onFulfilled, onRejected: deferred.onRejected))
            lock.unlock()
            promise.onResolve(fulfill: weakify(Promise.fulfill), reject: weakify(Promise.reject))
            
        default:
            fatalError("Duplicate attempt to resolve promise")
        }
    }

