Skip to content

Commit 3a67732

Browse files
committed
Define ~= for DispatchQueues, add more DispatchQueue identity tests (Linux)
1 parent bab67db commit 3a67732

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Sources/Configuration.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ public struct PMKConfiguration {
6767
switch dispatcher {
6868
case nil:
6969
return CurrentThreadDispatcher()
70-
case DispatchQueue.unspecified:
70+
case DispatchQueue.unspecified?:
7171
return nil // Do nothing
72-
case DispatchQueue.default:
72+
case DispatchQueue.default?:
7373
return `default`
74-
case DispatchQueue.chain:
74+
case DispatchQueue.chain?:
7575
fatalError("PromiseKit: .chain is not meaningful in the context of setDefaultDispatchers")
7676
default:
7777
return dispatcher!

Sources/Dispatcher.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,9 @@ extension Optional where Wrapped: DispatchQueue {
130130
return CurrentThreadDispatcher()
131131
}
132132
}
133+
134+
extension DispatchQueue {
135+
static func ~=(_ a: DispatchQueue, _ b: DispatchQueue) -> Bool {
136+
return a === b
137+
}
138+
}

Tests/Core/DispatcherTests.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ class DispatcherTests: XCTestCase {
6161
conf.D = oldConf
6262
}
6363

64-
func testPMKDefaultIdentity() {
65-
// If this identity does not hold, the DispatchQueue wrapper API will not behave correctly
64+
func testDispatchQueueIdentities() {
65+
// If these identities does not hold, the DispatchQueue wrapper API will not behave correctly
6666
XCTAssert(DispatchQueue.unspecified === DispatchQueue.unspecified, "DispatchQueues are not object-identity-preserving on this platform")
67+
XCTAssert(DispatchQueue.chain === DispatchQueue.chain, "DispatchQueues are not object-identity-preserving on this platform")
68+
XCTAssert(DispatchQueue.default === DispatchQueue.default, "DispatchQueues are not object-identity-preserving on this platform")
69+
XCTAssert(DispatchQueue.unspecified !== DispatchQueue.chain, "DispatchQueues are not object-identity-preserving on this platform")
70+
XCTAssert(DispatchQueue.chain !== DispatchQueue.default, "DispatchQueues are not object-identity-preserving on this platform")
71+
XCTAssert(DispatchQueue.default !== DispatchQueue.unspecified, "DispatchQueues are not object-identity-preserving on this platform")
6772
}
6873

6974
func testDispatcherWithThrow() {

0 commit comments

Comments
 (0)