diff --git a/README.md b/README.md index 308e339a10c..57c119bf7f9 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![codebeat badge](https://codebeat.co/badges/768d3017-1e65-47e0-b287-afcb8954a1da)](https://codebeat.co/projects/github-com-s4cha-then) [![Join the chat at https://gitter.im/s4cha/then](https://badges.gitter.im/s4cha/then.svg)](https://gitter.im/s4cha/then?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![License: MIT](http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/freshOS/then/blob/master/LICENSE) -[![Release version](https://img.shields.io/badge/release-2.2-blue.svg)]() + tag](https://img.shields.io/github/release/freshos/then.svg)]() [Reason](#why) - [Example](#example) - [Documentation](#documentation) - [Installation](#installation) @@ -391,14 +391,14 @@ 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.1** +Swift 4 -> version **3.0.2** ### Backers -Like the project? Offer coffee or support us with a monthly donation and help us continue our activities :) +Like the project? Offer coffee or support us with a monthly donation and help us continue our activities :) @@ -432,7 +432,7 @@ Like the project? Offer coffee or support us with a monthly donation and help us ### Sponsors -Become a sponsor and get your logo on our README on Github with a link to your site :) +Become a sponsor and get your logo on our README on Github with a link to your site :) diff --git a/Source/Info.plist b/Source/Info.plist index dc2b99a3b47..49ca846dfcf 100644 --- a/Source/Info.plist +++ b/Source/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.0.1 + 3.0.2 CFBundleSignature ???? CFBundleVersion diff --git a/Source/Promise+Recover.swift b/Source/Promise+Recover.swift index f3893205463..81889ff095e 100644 --- a/Source/Promise+Recover.swift +++ b/Source/Promise+Recover.swift @@ -25,7 +25,7 @@ extension Promise { syncStateWithCallBacks( success: p.fulfill, failure: { e in - if errorMatchesExpectedError(e, expectedError:errorType) { + if errorMatchesExpectedError(e, expectedError: errorType) { p.fulfill(value) } else { p.reject(e) @@ -40,7 +40,7 @@ extension Promise { syncStateWithCallBacks( success: p.fulfill, failure: { e in - if errorMatchesExpectedError(e, expectedError:errorType) { + if errorMatchesExpectedError(e, expectedError: errorType) { p.fulfill(value) } else { p.reject(e) diff --git a/Source/Promise.swift b/Source/Promise.swift index aef0a7eb9ed..0e9b2eef55c 100644 --- a/Source/Promise.swift +++ b/Source/Promise.swift @@ -118,7 +118,7 @@ public class Promise { } internal func reject(_ anError: Error) { - updateState(PromiseState.rejected(error: anError)) + updateState(PromiseState.rejected(error: anError)) // Only release callbacks if no retries a registered. if numberOfRetries == 0 { blocks = PromiseBlocks() diff --git a/Source/PromiseError.swift b/Source/PromiseError.swift index 59e58870922..3f9bba2ecb1 100644 --- a/Source/PromiseError.swift +++ b/Source/PromiseError.swift @@ -29,7 +29,7 @@ public func == (lhs: PromiseError, rhs: PromiseError) -> Bool { return true case (.raceAllFailed, .raceAllFailed): return true - case (.unwrappingFailed, .unwrappingFailed): + case (.unwrappingFailed, .unwrappingFailed): return true default: return false diff --git a/Source/WhenAll.swift b/Source/WhenAll.swift index f3c07a10812..8fac55efdb9 100644 --- a/Source/WhenAll.swift +++ b/Source/WhenAll.swift @@ -13,7 +13,7 @@ public class Promises {} extension Promises { - public static func whenAll(_ promises: [Promise]) -> Promise<[T]> { + public static func whenAll(_ promises: [Promise], callbackQueue: DispatchQueue? = nil) -> Promise<[T]> { let p = Promise<[T]>() var ts = [T]() var error: Error? @@ -25,7 +25,7 @@ extension Promises { .finally { group.leave() } } let callingQueue = OperationQueue.current?.underlyingQueue - let queue = callingQueue ?? DispatchQueue.main + let queue = callbackQueue ?? callingQueue ?? DispatchQueue.main group.notify(queue: queue) { if let e = error { p.reject(e) @@ -36,13 +36,13 @@ extension Promises { return p } - public static func whenAll(_ promises: Promise...) -> Promise<[T]> { - return whenAll(promises) + public static func whenAll(_ promises: Promise..., callbackQueue: DispatchQueue? = nil) -> Promise<[T]> { + return whenAll(promises, callbackQueue: callbackQueue) } // Array version - public static func whenAll(_ promises: [Promise<[T]>]) -> Promise<[T]> { + public static func whenAll(_ promises: [Promise<[T]>], callbackQueue: DispatchQueue? = nil) -> Promise<[T]> { let p = Promise<[T]>() var ts = [T]() var error: Error? @@ -54,7 +54,7 @@ extension Promises { .finally { group.leave() } } let callingQueue = OperationQueue.current?.underlyingQueue - let queue = callingQueue ?? DispatchQueue.main + let queue = callbackQueue ?? callingQueue ?? DispatchQueue.main group.notify(queue: queue) { if let e = error { p.reject(e) @@ -65,7 +65,7 @@ extension Promises { return p } - public static func whenAll(_ promises: Promise<[T]>...) -> Promise<[T]> { - return whenAll(promises) + public static func whenAll(_ promises: Promise<[T]>..., callbackQueue: DispatchQueue? = nil) -> Promise<[T]> { + return whenAll(promises, callbackQueue: callbackQueue) } } diff --git a/then.framework.zip b/then.framework.zip index c2f32226d21..4e9d659a9ac 100644 Binary files a/then.framework.zip and b/then.framework.zip differ diff --git a/thenMacOS/Info.plist b/thenMacOS/Info.plist index 8fcb79c677e..147af11b8e1 100644 --- a/thenMacOS/Info.plist +++ b/thenMacOS/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.0.1 + 3.0.2 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSHumanReadableCopyright diff --git a/thenPromise.podspec b/thenPromise.podspec index f3274ea6cc4..b7c63f91977 100644 --- a/thenPromise.podspec +++ b/thenPromise.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'thenPromise' - s.version = "3.0.1" + s.version = "3.0.2" s.summary = "Elegant Promises for Swift" s.homepage = "https://github.com/freshOS/then" s.license = { :type => "MIT", :file => "LICENSE" } diff --git a/thenTests/AsyncAwaitTests.swift b/thenTests/AsyncAwaitTests.swift index d765c8f959d..0bf364e4e2d 100644 --- a/thenTests/AsyncAwaitTests.swift +++ b/thenTests/AsyncAwaitTests.swift @@ -29,7 +29,7 @@ class AsyncAwaitTests: XCTestCase { let exp = expectation(description: "") async { _ = try await(failingFetchUserFollowStatusFromName("JohnDoe")) - XCTFail() + XCTFail("testFailingAsyncAwait failed") }.onError { _ in exp.fulfill() } @@ -40,7 +40,7 @@ class AsyncAwaitTests: XCTestCase { let exp = expectation(description: "") do { _ = try await(failingFetchUserFollowStatusFromName("JohnDoe")) - XCTFail() + XCTFail("testCatchFailingAsyncAwait failed") } catch { exp.fulfill() } diff --git a/thenTests/BridgeErrorTests.swift b/thenTests/BridgeErrorTests.swift index 6cd411dcf44..92c833d99c4 100644 --- a/thenTests/BridgeErrorTests.swift +++ b/thenTests/BridgeErrorTests.swift @@ -21,7 +21,7 @@ class BridgeErrorTests: XCTestCase { if let e = e as? MyError { XCTAssertTrue(e == .defaultError) } else { - XCTFail() + XCTFail("testBridgeAllErrorsToMine failed") } exp.fulfill() } @@ -51,7 +51,7 @@ class BridgeErrorTests: XCTestCase { if let e = e as? MyError { XCTAssertTrue(e == .defaultError) } else { - XCTFail() + XCTFail("testBridgeASpecificErrorToMine failed") } exp.fulfill() } @@ -68,7 +68,7 @@ class BridgeErrorTests: XCTestCase { if let e = e as? PromiseError { XCTAssertTrue(e == .default) } else { - XCTFail() + XCTFail("testBridgeASpecificErrorToMineNotMatchingError failed") } exp.fulfill() } @@ -87,7 +87,7 @@ class BridgeErrorTests: XCTestCase { if let e = e as? MyError { XCTAssertTrue(e == .defaultError) } else { - XCTFail() + XCTFail("failed testBridgeErrorCanUseBlockAndThrow") } exp.fulfill() } diff --git a/thenTests/ChainTests.swift b/thenTests/ChainTests.swift index c8f1bc7a1fa..d1189000ebf 100644 --- a/thenTests/ChainTests.swift +++ b/thenTests/ChainTests.swift @@ -32,7 +32,7 @@ class ChainTests: XCTestCase { func testChainNotCalledWhenSyncPromiseFails() { let exp = expectation(description: "") Promise.reject().chain { _ in - XCTFail() + XCTFail("testChainNotCalledWhenSyncPromiseFails failed") }.onError { _ in exp.fulfill() } @@ -42,7 +42,7 @@ class ChainTests: XCTestCase { func testChainNotCalledWhenAsyncPromiseFails() { let exp = expectation(description: "") failingFetchUserFollowStatusFromName("Tom").chain { _ in - XCTFail() + XCTFail("testChainNotCalledWhenAsyncPromiseFails failed") }.onError { _ in exp.fulfill() } diff --git a/thenTests/DelayTests.swift b/thenTests/DelayTests.swift index a090f42c588..b2c201d6d89 100644 --- a/thenTests/DelayTests.swift +++ b/thenTests/DelayTests.swift @@ -72,7 +72,7 @@ class DelayTests: XCTestCase { reject(PromiseError.default) } }.delay(0.8).then { _ in - XCTFail() + XCTFail("testDelayOnlyAppliesOnSuccessfulPromises failed") }.onError { _ in done = true e.fulfill() diff --git a/thenTests/FinallyTests.swift b/thenTests/FinallyTests.swift index 15774280867..025004b379e 100644 --- a/thenTests/FinallyTests.swift +++ b/thenTests/FinallyTests.swift @@ -75,7 +75,7 @@ class FinallyTests: XCTestCase { func testRegisterFinallyDoesntStartThePromise() { let exp = expectation(description: "error block called") syncRejectionPromise().registerFinally { - XCTFail() + XCTFail("testRegisterFinallyDoesntStartThePromise failed") } waitTime(1) { exp.fulfill() diff --git a/thenTests/OnErrorTests.swift b/thenTests/OnErrorTests.swift index bdadf066f12..dfb45a3ba93 100644 --- a/thenTests/OnErrorTests.swift +++ b/thenTests/OnErrorTests.swift @@ -114,7 +114,7 @@ class OnErrorTests: XCTestCase { func testRegisterOnErrorDoesntStartThePromise() { let exp = expectation(description: "error block called") syncRejectionPromise().registerOnError { _ in - XCTFail() + XCTFail("testRegisterOnErrorDoesntStartThePromise failed") } waitTime(1) { exp.fulfill() diff --git a/thenTests/ProgressTests.swift b/thenTests/ProgressTests.swift index 2358ffb494e..05fe4d52e1e 100644 --- a/thenTests/ProgressTests.swift +++ b/thenTests/ProgressTests.swift @@ -34,7 +34,7 @@ class ProgressTests: XCTestCase { XCTAssertEqual(p, 0.8) progressExpectation.fulfill() }.then { - XCTFail() + XCTFail("testProgressFails failed") }.onError { _ in errorExpectation.fulfill() } diff --git a/thenTests/RaceTests.swift b/thenTests/RaceTests.swift index 0f78cac821a..aa07c20a511 100644 --- a/thenTests/RaceTests.swift +++ b/thenTests/RaceTests.swift @@ -50,7 +50,7 @@ class RaceTests: XCTestCase { let p1 = Promise.reject() let p2 = Promise.reject() Promises.race(p1, p2).then { _ in - XCTFail() + XCTFail("testRaceFailsIfAllFail failed") }.onError { _ in e.fulfill() } diff --git a/thenTests/RecoverTests.swift b/thenTests/RecoverTests.swift index 530360b10c6..0bbf087f8d4 100644 --- a/thenTests/RecoverTests.swift +++ b/thenTests/RecoverTests.swift @@ -84,7 +84,7 @@ class RecoverTests: XCTestCase { if let e = e as? MyError { XCTAssertTrue(e == .defaultError) } else { - XCTFail() + XCTFail("testRecoverCanThrowANewError failed") } exp.fulfill() } @@ -108,7 +108,7 @@ class RecoverTests: XCTestCase { Promise.reject() .recover(PromiseError.validationFailed, with: 123) .then { _ in - XCTFail() + XCTFail("testRecoverForSpecificErrorDoesNotRecoverWhenTypeNotMatching failed") }.onError { _ in exp.fulfill() } @@ -127,7 +127,7 @@ class RecoverTests: XCTestCase { } struct SomeError: Error { } -extension SomeError :Equatable { } +extension SomeError: Equatable { } func == (lhs: SomeError, rhs: SomeError) -> Bool { return true } diff --git a/thenTests/RegisterThenTests.swift b/thenTests/RegisterThenTests.swift index 468a454ac32..1394d5b6e90 100644 --- a/thenTests/RegisterThenTests.swift +++ b/thenTests/RegisterThenTests.swift @@ -15,11 +15,11 @@ class RegisterThenTests: XCTestCase { let timerExpectation = expectation(description: "timerExpectation") fetchUserId() .registerThen { _ in - XCTFail() + XCTFail("testRegisterThenChainedPromisesAreNeverCalledWithoutAThenBlock failed") }.registerThen {_ in - XCTFail() + XCTFail("testRegisterThenChainedPromisesAreNeverCalledWithoutAThenBlock failed") }.registerThen {_ in - XCTFail() + XCTFail("testRegisterThenChainedPromisesAreNeverCalledWithoutAThenBlock failed") } waitTime(1) { timerExpectation.fulfill() @@ -32,11 +32,11 @@ class RegisterThenTests: XCTestCase { fetchUserId() .registerThen(fetchUserNameFromId(10)).registerThen { name in print(name) - XCTFail() + XCTFail("testRegisterThenPromiseChainedPromisesAreNeverCalledWithoutAThenBlock failed") }.registerThen {_ in - XCTFail() + XCTFail("testRegisterThenPromiseChainedPromisesAreNeverCalledWithoutAThenBlock failed") }.registerThen {_ in - XCTFail() + XCTFail("testRegisterThenPromiseChainedPromisesAreNeverCalledWithoutAThenBlock failed") } waitTime(1) { timerExpectation.fulfill() @@ -48,11 +48,10 @@ class RegisterThenTests: XCTestCase { let timerExpectation = expectation(description: "timerExpectation") fetchUserId().registerThen { id in return fetchUserNameFromId(id) - }.registerThen { name in - print(name) - XCTFail() }.registerThen { _ in - XCTFail() + XCTFail("testRegisterThenPromise2ChainedPromisesAreNeverCalledWithoutAThenBlock failed") + }.registerThen { _ in + XCTFail("testRegisterThenPromise2ChainedPromisesAreNeverCalledWithoutAThenBlock failed") } waitTime(1) { timerExpectation.fulfill() @@ -95,7 +94,7 @@ class RegisterThenTests: XCTestCase { fetchUserId() .registerThen(fetchUserNameFromId) .registerThen { _ in - XCTFail() + XCTFail("testRegisterThenPromiseFuncPointerNotCalled failed") } waitTime(1) { timerExpectation.fulfill() @@ -108,7 +107,7 @@ class RegisterThenTests: XCTestCase { fetchUserId().registerThen { id -> Promise in return fetchUserNameFromId(id) }.registerThen { _ in - XCTFail() + XCTFail("testRegisterThenPromise2FuncPointerNotCalled failed") } waitTime(1) { timerExpectation.fulfill() diff --git a/thenTests/RetryTests.swift b/thenTests/RetryTests.swift index a20f9d0fe0a..aaada94c334 100644 --- a/thenTests/RetryTests.swift +++ b/thenTests/RetryTests.swift @@ -17,7 +17,7 @@ class RetryTests: XCTestCase { let e = expectation(description: "") testPromise() .retry(5).then { - XCTFail() + XCTFail("testRetryNumberWhenKeepsFailing failed") }.onError { _ in e.fulfill() XCTAssertEqual(5, self.tryCount) @@ -32,7 +32,7 @@ class RetryTests: XCTestCase { e.fulfill() XCTAssertEqual(3, self.tryCount) }.onError { _ in - XCTFail() + XCTFail("testRetrySucceedsAfter3times failed") } waitForExpectations(timeout: 1, handler: nil) } diff --git a/thenTests/ThenTests.swift b/thenTests/ThenTests.swift index 97c1ad015ba..2b8e299a61f 100644 --- a/thenTests/ThenTests.swift +++ b/thenTests/ThenTests.swift @@ -133,7 +133,7 @@ class ThenTests: XCTestCase { let thenExpectation = expectation(description: "then called") let errorExpectation = expectation(description: "Finally called") failingFetchUserFollowStatusFromName("").then { _ in - XCTFail() + XCTFail("testCanContinueWithThenAfterErrorBlock failed") }.onError { _ in errorExpectation.fulfill() }.then { diff --git a/thenTests/TimeoutTests.swift b/thenTests/TimeoutTests.swift index 83d02dbf348..1fd72bbf3a0 100644 --- a/thenTests/TimeoutTests.swift +++ b/thenTests/TimeoutTests.swift @@ -21,7 +21,7 @@ class TimeoutTests: XCTestCase { XCTAssertEqual(string, "Hello") e.fulfill() }.onError { _ in - XCTFail() + XCTFail("testTimeOutTriggers failed") } waitForExpectations(timeout: 5, handler: nil) } @@ -33,12 +33,12 @@ class TimeoutTests: XCTestCase { resolve("Hello") } }.timeout(0.5).then { _ in - XCTFail() + XCTFail("testTimeOutFails failed") }.onError { error in if case PromiseError.timeout = error { // Good } else { - XCTFail() + XCTFail("testTimeOutFails failed") } e.fulfill() } diff --git a/thenTests/UnwrapTests.swift b/thenTests/UnwrapTests.swift index 06f7ae1817a..9e415bae943 100644 --- a/thenTests/UnwrapTests.swift +++ b/thenTests/UnwrapTests.swift @@ -16,19 +16,19 @@ class UnwrapTests: XCTestCase { unwrap(username).then { s in XCTAssertEqual(s, username) }.onError { _ in - XCTFail() + XCTFail("testUwrap failed") } } func testUwrapFails() { let username: String? = nil unwrap(username).then { _ in - XCTFail() + XCTFail("testUwrapFails failed") }.onError { e in if let pe = e as? PromiseError { XCTAssertTrue(pe == .unwrappingFailed) } else { - XCTFail() + XCTFail("testUwrapFails failed") } } } diff --git a/thenTests/ValidateTests.swift b/thenTests/ValidateTests.swift index 0a52105346e..b644d7c55c2 100644 --- a/thenTests/ValidateTests.swift +++ b/thenTests/ValidateTests.swift @@ -29,7 +29,7 @@ class ValidateTests: XCTestCase { if let pe = error as? PromiseError { XCTAssertTrue(pe == .validationFailed) } else { - XCTFail() + XCTFail("testValidateFails failed") } e.fulfill() } @@ -44,7 +44,7 @@ class ValidateTests: XCTestCase { if let pe = error as? MyError { XCTAssertTrue(pe == MyError.defaultError) } else { - XCTFail() + XCTFail("testValidateWithCustomError failed") } e.fulfill() } @@ -54,7 +54,7 @@ class ValidateTests: XCTestCase { func testValidateNotCalledOnError() { let e = expectation(description: "") Promise.reject().validate { - XCTFail() + XCTFail("testValidateNotCalledOnError failed") return true }.finally { e.fulfill() diff --git a/thenTests/WhenAllTests.swift b/thenTests/WhenAllTests.swift index 81bd4b9f5ff..4d4c3204d91 100644 --- a/thenTests/WhenAllTests.swift +++ b/thenTests/WhenAllTests.swift @@ -65,7 +65,7 @@ class WhenAllTests: XCTestCase { Promises.whenAll(promise1, promise2) .then { _ in - XCTFail() + XCTFail("testWhenAllCallsOnErrorWhenOneFailsSynchronous failed") }.onError { _ in block.fulfill() }.finally { @@ -89,7 +89,7 @@ class WhenAllTests: XCTestCase { } Promises.whenAll(promise1, promise2) .then { _ in - XCTFail() + XCTFail("testWhenAllCallsOnErrorWhenOneFailsAsynchronous failed") }.onError { _ in block.fulfill() }.finally { diff --git a/thenTests/ZipTests.swift b/thenTests/ZipTests.swift index 77897a44a69..af9eab4141a 100644 --- a/thenTests/ZipTests.swift +++ b/thenTests/ZipTests.swift @@ -42,7 +42,7 @@ class ZipTests: XCTestCase { func testZipSynchronousPromisesFails() { let block = expectation(description: "Block called") Promises.zip(Promise.reject(), Promise("Hello")).then { _, _ in - XCTFail() + XCTFail("testZipSynchronousPromisesFails failed") }.onError { _ in block.fulfill() } @@ -58,7 +58,7 @@ class ZipTests: XCTestCase { waitTime(0.1) { reject(PromiseError.default) } } Promises.zip(p1, p2).then { _, _ in - XCTFail() + XCTFail("testZipAsynchronousPromisesFails failed") }.onError { _ in block.fulfill() } @@ -102,7 +102,7 @@ class ZipTests: XCTestCase { func testZip3SynchronousPromisesFails() { let block = expectation(description: "Block called") Promises.zip(Promise.reject(), Promise("Hello"), Promise.reject()).then { _, _, _ in - XCTFail() + XCTFail("testZip3SynchronousPromisesFails failed") }.onError { _ in block.fulfill() } @@ -121,7 +121,7 @@ class ZipTests: XCTestCase { waitTime(0.1) { resolve(0.45) } } Promises.zip(p1, p2, p3).then { _, _, _ in - XCTFail() + XCTFail("testZip3AsynchronousPromisesFails failed") }.onError { _ in block.fulfill() } diff --git a/thenTvOS/Info.plist b/thenTvOS/Info.plist index 4b187ebf592..5ca78f13a35 100644 --- a/thenTvOS/Info.plist +++ b/thenTvOS/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.0.1 + 3.0.2 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass