Skip to content

Commit

Permalink
Bumps to 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
s4cha committed Feb 5, 2018
1 parent ca7648d commit 664697d
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Grab this repository and build the Framework target on the example project. Then
## Swift Version
Swift 2 -> version **1.4.2**
Swift 3 -> version **2.2.5**
Swift 4 -> version **3.0.2**
Swift 4 -> version **3.1.0**

<!-- Place this tag in your head or just before your close body tag. -->
<script async defer src="https://buttons.github.io/buttons.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion Source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.0.2</string>
<string>3.1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
57 changes: 40 additions & 17 deletions Source/Promise+Zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,64 @@ import Dispatch
extension Promises {

public static func zip<T, U>(_ p1: Promise<T>, _ p2: Promise<U>) -> Promise<(T, U)> {

let p = Promise<(T, U)>()
var t: T!
var u: U!
var error: Error?
let group = DispatchGroup()

// pass the current quuere?
let concurentQueue = DispatchQueue(label: "concurrent", attributes: .concurrent)
// We run the promises concurrently on a concurent queue and go back
// to a local queue to read/modify global variables.
// .barrier blocks concurrency so that we can write values
// without then beeing read at the same time.
// It pauses reads until write are done
let concurentQueue = DispatchQueue(label: "then.zip.concurrent", attributes: .concurrent)
let localQueue = DispatchQueue(label: "then.zip.local", attributes: .concurrent)

group.enter()
concurentQueue.async {
//p1

p1.then { t = $0 }
.onError { error = $0 }
.finally { group.leave() }

p1.then { aT in
localQueue.async(flags: .barrier) {
t = aT
}
}.onError { e in
localQueue.async(flags: .barrier) {
error = e
}
}.finally {
localQueue.async { // barrier needed?
group.leave()
}
}
}

group.enter()
concurentQueue.async {
//p2
p2.then { u = $0 }
.onError { error = $0 }
.finally { group.leave() }

p2.then { aU in
localQueue.async(flags: .barrier) {
u = aU
}
}.onError { e in
localQueue.async(flags: .barrier) {
error = e
}
}.finally {
localQueue.async {
group.leave()
}
}
}

let callingQueue = OperationQueue.current?.underlyingQueue
let queue = callingQueue ?? DispatchQueue.main
group.notify(queue: queue) {
if let e = error {
p.reject(e)
} else {
p.fulfill((t, u))
localQueue.async {
if let e = error {
p.reject(e)
} else {
p.fulfill((t, u))
}
}
}
return p
Expand Down
4 changes: 2 additions & 2 deletions Source/Promise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public class Promise<T> {
}
}

internal func fulfill(_ value: T) {
public func fulfill(_ value: T) {
updateState(PromiseState<T>.fulfilled(value: value))
blocks = PromiseBlocks<T>()
promiseProgressCallBack = nil
}

internal func reject(_ anError: Error) {
public func reject(_ anError: Error) {
updateState(PromiseState<T>.rejected(error: anError))
// Only release callbacks if no retries a registered.
if numberOfRetries == 0 {
Expand Down
Binary file modified then.framework.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion thenMacOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.0.2</string>
<string>3.1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
2 changes: 1 addition & 1 deletion thenPromise.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'thenPromise'
s.version = "3.0.2"
s.version = "3.1.0"
s.summary = "Elegant Promises for Swift"
s.homepage = "https://github.com/freshOS/then"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
2 changes: 1 addition & 1 deletion thenTests/RaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RaceTests: XCTestCase {
}
}
Promises.race(p1, p2).onError { error in
guard let _ = error as? TestRaceError else {
guard error as? TestRaceError != nil else {
XCTFail("testRecoverCanThrowANewError failed")
return
}
Expand Down
36 changes: 35 additions & 1 deletion thenTests/RecoverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RecoverTests: XCTestCase {
func testRecoverCanThrowANewError() {
let exp = expectation(description: "")
Promise<Int>.reject()
.recover { e in
.recover { e -> Int in
if let e = e as? PromiseError, e == .default {
throw MyError.defaultError
}
Expand Down Expand Up @@ -124,6 +124,40 @@ class RecoverTests: XCTestCase {
}
waitForExpectations(timeout: 0.3, handler: nil)
}

func testRecoverPromiseBlockCanUseABlock() {
let e = expectation(description: "")
Promise<Int>.reject()
.recover { _ in
return Promise(32)
}
.then { s in
XCTAssertEqual(s, 32)
e.fulfill()
}
waitForExpectations(timeout: 0.3, handler: nil)
}

func testRecoverPromiseBlockCanThrowANewError() {
let exp = expectation(description: "")
Promise<Int>.reject()
.recover { e -> Promise<Int> in
if let e = e as? PromiseError, e == .default {
throw MyError.defaultError
}
return Promise(32)
} .then { _ in
XCTFail("then shouldn't be called")
}.onError { e in
if let e = e as? MyError {
XCTAssertTrue(e == .defaultError)
} else {
XCTFail("testRecoverCanThrowANewError failed")
}
exp.fulfill()
}
waitForExpectations(timeout: 0.3, handler: nil)
}
}

struct SomeError: Error { }
Expand Down
2 changes: 1 addition & 1 deletion thenTvOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.0.2</string>
<string>3.1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down

0 comments on commit 664697d

Please sign in to comment.