Skip to content

Commit

Permalink
Merge pull request malcommac#78 from malcommac/bug/77-fix-chainable-t…
Browse files Browse the repository at this point in the history
…hens-xcode12

[malcommac#77] [Bug] Fixed chainable thens operators in Xcode 12/Swift 5.3
  • Loading branch information
malcommac authored Sep 14, 2020
2 parents 5535aa9 + 80cea65 commit 43170f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Hydra/Promise+Cancel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public extension Promise {
/// - body: body to execute
/// - Returns: a new void promise
@discardableResult
func cancelled(in context: Context? = nil, _ body: @escaping (() -> (()))) -> Promise<Void> {
func cancelled(in context: Context? = nil, _ body: @escaping (() -> (Void))) -> Promise<Void> {
let ctx = context ?? .main
let nextPromise = Promise<Void>(in: ctx, token: self.invalidationToken) { resolve, reject, operation in
let onResolve = Observer.onResolve(ctx, { _ in
Expand Down
17 changes: 17 additions & 0 deletions Tests/HydraTests/HydraTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,23 @@ class HydraTestThen: XCTestCase {
}
waitForExpectations(timeout: expTimeout, handler: nil)
}

func test_thenChainAndAlways() {
let exp = expectation(description: "test_anyWithArray")
var passedThens = 0

Promise<Int>(in: .background, token: nil) { (r, rj, s) in
r(10)
}.then { _ in
passedThens += 1
}.always(in: .main) {
passedThens += 1
XCTAssertTrue(passedThens == 2, "Not all thens are passed")
XCTAssertTrue(Thread.isMainThread, "Failed, the operation is not on main thread as we expect")
exp.fulfill()
}
waitForExpectations(timeout: expTimeout, handler: nil)
}

/// The same test with `any` operator which takes as input an array instead of variable list of arguments
func test_anyWithArray() {
Expand Down

0 comments on commit 43170f5

Please sign in to comment.