Skip to content

Commit

Permalink
Define ~= for DispatchQueues, add more DispatchQueue identity tests (…
Browse files Browse the repository at this point in the history
…Linux)
  • Loading branch information
GarthSnyder committed Apr 24, 2019
1 parent bab67db commit 3a67732
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Sources/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public struct PMKConfiguration {
switch dispatcher {
case nil:
return CurrentThreadDispatcher()
case DispatchQueue.unspecified:
case DispatchQueue.unspecified?:
return nil // Do nothing
case DispatchQueue.default:
case DispatchQueue.default?:
return `default`
case DispatchQueue.chain:
case DispatchQueue.chain?:
fatalError("PromiseKit: .chain is not meaningful in the context of setDefaultDispatchers")
default:
return dispatcher!
Expand Down
6 changes: 6 additions & 0 deletions Sources/Dispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,9 @@ extension Optional where Wrapped: DispatchQueue {
return CurrentThreadDispatcher()
}
}

extension DispatchQueue {
static func ~=(_ a: DispatchQueue, _ b: DispatchQueue) -> Bool {
return a === b
}
}
9 changes: 7 additions & 2 deletions Tests/Core/DispatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ class DispatcherTests: XCTestCase {
conf.D = oldConf
}

func testPMKDefaultIdentity() {
// If this identity does not hold, the DispatchQueue wrapper API will not behave correctly
func testDispatchQueueIdentities() {
// If these identities does not hold, the DispatchQueue wrapper API will not behave correctly
XCTAssert(DispatchQueue.unspecified === DispatchQueue.unspecified, "DispatchQueues are not object-identity-preserving on this platform")
XCTAssert(DispatchQueue.chain === DispatchQueue.chain, "DispatchQueues are not object-identity-preserving on this platform")
XCTAssert(DispatchQueue.default === DispatchQueue.default, "DispatchQueues are not object-identity-preserving on this platform")
XCTAssert(DispatchQueue.unspecified !== DispatchQueue.chain, "DispatchQueues are not object-identity-preserving on this platform")
XCTAssert(DispatchQueue.chain !== DispatchQueue.default, "DispatchQueues are not object-identity-preserving on this platform")
XCTAssert(DispatchQueue.default !== DispatchQueue.unspecified, "DispatchQueues are not object-identity-preserving on this platform")
}

func testDispatcherWithThrow() {
Expand Down

0 comments on commit 3a67732

Please sign in to comment.