Skip to content

Commit

Permalink
'Cancel' for PromiseKit: fix for #1026, plus cleanup
Browse files Browse the repository at this point in the history
* Fix "Typechecking timeout compiling tests in v7 #1026" by specifying the closure return type in DispatcherTests
* Remove unnecessary "#if swift" checks in the cancellable code and tests
  • Loading branch information
dougzilla32 authored and mxcl committed Apr 7, 2019
1 parent 34e3114 commit 087f066
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 42 deletions.
2 changes: 0 additions & 2 deletions Sources/CancellablePromise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public class CancellablePromise<T>: CancellableThenable, CancellableCatchMixin {
}
}

#if swift(>=3.1)
extension CancellablePromise where T == Void {
/// Initializes a new cancellable promise fulfilled with `Void`
public convenience init() {
Expand All @@ -140,4 +139,3 @@ extension CancellablePromise where T == Void {
self.appendCancellable(cancellable, reject: nil)
}
}
#endif
4 changes: 0 additions & 4 deletions Tests/Cancel/CancelChain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ class CancelChain: XCTestCase {

self.trace("SETUP COMPLETE")

#if swift(>=4.1)
let expectations = [ex.a, ex.b, ex.c, ex.d, ex.e, ex.cancelled].compactMap { $0 }
#else
let expectations = [ex.a, ex.b, ex.c, ex.d, ex.e, ex.cancelled].flatMap { $0 }
#endif
wait(for: expectations, timeout: 1)

XCTAssert(c.pA.cancelContext.cancelAttempted)
Expand Down
2 changes: 0 additions & 2 deletions Tests/Cancel/CancellableErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,12 @@ class CancellationTests: XCTestCase {
waitForExpectations(timeout: 1)
}

#if swift(>=3.2)
func testIsCancelled() {
XCTAssertTrue(PMKError.cancelled.isCancelled)
XCTAssertTrue(URLError.cancelled.isCancelled)
XCTAssertTrue(CocoaError.cancelled.isCancelled)
XCTAssertFalse(CocoaError(_nsError: NSError(domain: NSCocoaErrorDomain, code: CocoaError.Code.coderInvalidValue.rawValue)).isCancelled)
}
#endif
}

private enum LocalError: CancellableError {
Expand Down
4 changes: 2 additions & 2 deletions Tests/Cancel/DispatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class DispatcherTests: XCTestCase {
Promise.value(v + 10).cancellize()
}.thenMap(on: .global(qos: .background), flags: .barrier) { v -> Promise<Int> in
Promise.value(v + 10)
}.thenFlatMap(on: .global(qos: .background), flags: .barrier) {
Promise.value([$0 + 10]).cancellize()
}.thenFlatMap(on: .global(qos: .background), flags: .barrier) { v -> CancellablePromise<[Int]> in
Promise.value([v + 10]).cancellize()
}.thenFlatMap(on: .global(qos: .background), flags: .barrier) { v -> Promise<[Int]> in
Promise.value([v + 10])
}.filterValues(on: .global(qos: .background), flags: .barrier) { _ in
Expand Down
16 changes: 0 additions & 16 deletions Tests/Cancel/GuaranteeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,10 @@ class GuaranteeTests: XCTestCase {
}

func testCancellable() {
#if swift(>=4.0)
var resolver: ((()) -> Void)!
#else
var resolver: ((Void) -> Void)!
#endif

let task = DispatchWorkItem {
#if swift(>=4.0)
resolver(())
#else
resolver()
#endif
}

q.asyncAfter(deadline: DispatchTime.now() + 0.5, execute: task)
Expand All @@ -76,18 +68,10 @@ class GuaranteeTests: XCTestCase {
}

func testSetCancellable() {
#if swift(>=4.0)
var resolver: ((()) -> Void)!
#else
var resolver: ((Void) -> Void)!
#endif

let task = DispatchWorkItem {
#if swift(>=4.0)
resolver(())
#else
resolver()
#endif
}

q.asyncAfter(deadline: DispatchTime.now() + 0.5, execute: task)
Expand Down
14 changes: 0 additions & 14 deletions Tests/Cancel/PromiseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ class PromiseTests: XCTestCase {
_ = CancellablePromise().map { Error.dummy }
}

#if swift(>=3.1)
func testCanMakeVoidPromise() {
_ = CancellablePromise()
_ = Guarantee()
}
#endif

enum Error: Swift.Error {
case dummy
Expand Down Expand Up @@ -154,11 +152,7 @@ class PromiseTests: XCTestCase {
var resolver: Resolver<Void>!

let task = DispatchWorkItem {
#if swift(>=4.0)
resolver.fulfill(())
#else
resolver.fulfill()
#endif
}

q.asyncAfter(deadline: DispatchTime.now() + 0.5, execute: task)
Expand All @@ -183,11 +177,7 @@ class PromiseTests: XCTestCase {
var resolver: Resolver<Void>!

let task = DispatchWorkItem {
#if swift(>=4.0)
resolver.fulfill(())
#else
resolver.fulfill()
#endif
}

q.asyncAfter(deadline: DispatchTime.now() + 0.5, execute: task)
Expand Down Expand Up @@ -215,11 +205,7 @@ class PromiseTests: XCTestCase {
var resolver: Resolver<Void>!

let task = DispatchWorkItem {
#if swift(>=4.0)
resolver.fulfill(())
#else
resolver.fulfill()
#endif
}

q.asyncAfter(deadline: DispatchTime.now() + 0.5, execute: task)
Expand Down
2 changes: 0 additions & 2 deletions Tests/Cancel/ResolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ class WrapTests: XCTestCase {
wait(for: [ex1, ex2] ,timeout: 1)
}

#if swift(>=3.1)
func testVoidCompletionValue() {
let ex1 = expectation(description: "")
let kf1 = KittenFetcher(value: nil, error: nil)
Expand Down Expand Up @@ -284,7 +283,6 @@ class WrapTests: XCTestCase {

wait(for: [ex1, ex2], timeout: 1)
}
#endif

func testIsFulfilled() {
let p1 = Promise.value(()).cancellize()
Expand Down

0 comments on commit 087f066

Please sign in to comment.