Skip to content

Commit

Permalink
Updating to the PromiseKit v6 #27
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickl committed Mar 3, 2018
1 parent b48a6c0 commit 7a806ad
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion AwaitKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ class ViewController: UIViewController {

func sendWelcomeMailToUser(_ user: User) -> Promise<Void> {
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<Void> {
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(())
})
}
}
Expand Down
27 changes: 12 additions & 15 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Sources/AwaitKit/AwaitKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct Queue {
- returns: A new promise that is resolved when the provided closure returned.
*/
public func async<T>(_ body: @escaping () throws -> T) -> Promise<T> {
return Queue.async.promise(execute: body)
return Queue.async.async(.promise, execute: body)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Sources/AwaitKit/DispatchQueue+Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(_ body: @escaping () throws -> T) -> Promise<T> {
return base.promise(execute: body)
return base.async(.promise, execute: body)
}

/**
Expand Down
10 changes: 6 additions & 4 deletions Sources/AwaitKit/DispatchQueue+Await.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension Extension where Base: DispatchQueue {
*/
@discardableResult
public final func await<T>(_ 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)
}
Expand All @@ -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<Void> 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)

Expand Down

0 comments on commit 7a806ad

Please sign in to comment.