From 7a806ad388e4c1f83823eb14ebfb6658cc8533fa Mon Sep 17 00:00:00 2001 From: Yannick Loriot Date: Sat, 3 Mar 2018 23:03:04 +0100 Subject: [PATCH] Updating to the PromiseKit v6 #27 --- AwaitKit.podspec | 2 +- Example/Example/ViewController.swift | 8 +++---- Example/Podfile.lock | 27 ++++++++++------------ Sources/AwaitKit/AwaitKit.swift | 2 +- Sources/AwaitKit/DispatchQueue+Async.swift | 2 +- Sources/AwaitKit/DispatchQueue+Await.swift | 10 ++++---- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/AwaitKit.podspec b/AwaitKit.podspec index 3a1e736..7eeed36 100644 --- a/AwaitKit.podspec +++ b/AwaitKit.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| s.ios.framework = 'Foundation' - s.dependency 'PromiseKit', '~> 4.5' + s.dependency 'PromiseKit', '~> 6' s.source_files = 'Sources/**/*.swift' s.requires_arc = true diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index d4b4dc3..c2037cc 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -39,24 +39,24 @@ class ViewController: UIViewController { func sendWelcomeMailToUser(_ user: User) -> Promise { print("sendWelcomeMailToUser") - return Promise { resolve, reject in + return Promise { seal in let deadlineTime = DispatchTime.now() + .seconds(1) let queue = DispatchQueue(label: "com.yannickloriot.queue", attributes: .concurrent) queue.asyncAfter(deadline: deadlineTime, execute: { - resolve(()) + seal.fulfill(()) }) } } func redirectToThankYouScreen() -> Promise { print("redirectToThankYouScreen") - return Promise { resolve, reject in + return Promise { seal in let deadlineTime = DispatchTime.now() + .seconds(1) let queue = DispatchQueue(label: "com.yannickloriot.queue", attributes: .concurrent) queue.asyncAfter(deadline: deadlineTime, execute: { - resolve(()) + seal.fulfill(()) }) } } diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 5d0c7d3..37b96d6 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,30 +1,27 @@ PODS: - - AwaitKit (3.0.2): - - PromiseKit (~> 4.5) - - PromiseKit (4.5.1): - - PromiseKit/Foundation (= 4.5.1) - - PromiseKit/QuartzCore (= 4.5.1) - - PromiseKit/UIKit (= 4.5.1) - - PromiseKit/CorePromise (4.5.1) - - PromiseKit/Foundation (4.5.1): + - AwaitKit (4.0.0): + - PromiseKit (~> 6) + - PromiseKit (6.2.0): + - PromiseKit/CorePromise (= 6.2.0) + - PromiseKit/Foundation (= 6.2.0) + - PromiseKit/UIKit (= 6.2.0) + - PromiseKit/CorePromise (6.2.0) + - PromiseKit/Foundation (6.2.0): - PromiseKit/CorePromise - - PromiseKit/QuartzCore (4.5.1): - - PromiseKit/CorePromise - - PromiseKit/UIKit (4.5.1): + - PromiseKit/UIKit (6.2.0): - PromiseKit/CorePromise DEPENDENCIES: - AwaitKit (from `..`) - - PromiseKit (~> 4.5) EXTERNAL SOURCES: AwaitKit: :path: .. SPEC CHECKSUMS: - AwaitKit: 9a35748cf3ee8838050109458f06cba1b3b39e64 - PromiseKit: 445dac9b2c3c3b4b31b5f842bc325700b848a8bd + AwaitKit: 4008c4fd2f2dbb75a8732b0c3f66935a46647981 + PromiseKit: ea9a155e1fd98a926ccfaf633c0fbd69851f0e7b -PODFILE CHECKSUM: 3e652443f3aabcc9f24b5b1c0595a710742e6603 +PODFILE CHECKSUM: 78e564670b78aa7f30da04815ee08a7f80131817 COCOAPODS: 1.4.0 diff --git a/Sources/AwaitKit/AwaitKit.swift b/Sources/AwaitKit/AwaitKit.swift index 82a6d5f..2aba30d 100644 --- a/Sources/AwaitKit/AwaitKit.swift +++ b/Sources/AwaitKit/AwaitKit.swift @@ -40,7 +40,7 @@ public struct Queue { - returns: A new promise that is resolved when the provided closure returned. */ public func async(_ body: @escaping () throws -> T) -> Promise { - return Queue.async.promise(execute: body) + return Queue.async.async(.promise, execute: body) } /** diff --git a/Sources/AwaitKit/DispatchQueue+Async.swift b/Sources/AwaitKit/DispatchQueue+Async.swift index b1e4b6d..e334270 100644 --- a/Sources/AwaitKit/DispatchQueue+Async.swift +++ b/Sources/AwaitKit/DispatchQueue+Async.swift @@ -36,7 +36,7 @@ extension Extension where Base: DispatchQueue { - Returns: A new promise that is resolved when the provided closure returned. */ public final func async(_ body: @escaping () throws -> T) -> Promise { - return base.promise(execute: body) + return base.async(.promise, execute: body) } /** diff --git a/Sources/AwaitKit/DispatchQueue+Await.swift b/Sources/AwaitKit/DispatchQueue+Await.swift index c215c1d..aa429bf 100644 --- a/Sources/AwaitKit/DispatchQueue+Await.swift +++ b/Sources/AwaitKit/DispatchQueue+Await.swift @@ -39,7 +39,7 @@ extension Extension where Base: DispatchQueue { */ @discardableResult public final func await(_ body: @escaping () throws -> T) throws -> T { - let promise = self.base.promise(execute: body) + let promise = self.base.async(.promise, execute: body) return try await(promise) } @@ -66,16 +66,18 @@ extension Extension where Base: DispatchQueue { let semaphore = DispatchSemaphore(value: 0) promise - .then(on: self.base) { value -> Void in + .then(on: self.base) { value -> Promise in result = value semaphore.signal() + + return Promise() } - .catch(on: self.base) { err in + .catch(on: self.base, policy: .allErrors) { err in error = err semaphore.signal() - } + } _ = semaphore.wait(timeout: .distantFuture)