From 660c913111886890474747055eef7d8d288a5747 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Tue, 27 Feb 2018 11:39:10 -0500 Subject: [PATCH] Fix throwing in init(resolver:) => warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Resolver deallocated pending, so it led to the pending promise warning. Aside: this of course means that we don’t warn for pending Guarantees or AnyPromises. Fixes #799 --- PromiseKit.xcodeproj/project.pbxproj | 4 ++-- Sources/Promise.swift | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/PromiseKit.xcodeproj/project.pbxproj b/PromiseKit.xcodeproj/project.pbxproj index 3326d628b..07bf294cf 100644 --- a/PromiseKit.xcodeproj/project.pbxproj +++ b/PromiseKit.xcodeproj/project.pbxproj @@ -823,7 +823,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 6.1.2; + CURRENT_PROJECT_VERSION = 6.2.0; DEBUG_INFORMATION_FORMAT = dwarf; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -884,7 +884,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 6.1.2; + CURRENT_PROJECT_VERSION = 6.2.0; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; diff --git a/Sources/Promise.swift b/Sources/Promise.swift index 5a5ed4e4c..74e111ed4 100644 --- a/Sources/Promise.swift +++ b/Sources/Promise.swift @@ -53,10 +53,11 @@ public class Promise: Thenable, CatchMixin { /// Initialize a new promise that can be resolved with the provided `Resolver`. public init(resolver body: (Resolver) throws -> Void) { box = EmptyBox() + let resolver = Resolver(box) do { - try body(Resolver(box)) + try body(resolver) } catch { - box.seal(.rejected(error)) + resolver.reject(error) } }