diff --git a/Sources/Configuration.swift b/Sources/Configuration.swift index 1355e23ab..3017ba7f0 100644 --- a/Sources/Configuration.swift +++ b/Sources/Configuration.swift @@ -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! diff --git a/Sources/Dispatcher.swift b/Sources/Dispatcher.swift index dcddd52e1..444a47bb9 100644 --- a/Sources/Dispatcher.swift +++ b/Sources/Dispatcher.swift @@ -130,3 +130,9 @@ extension Optional where Wrapped: DispatchQueue { return CurrentThreadDispatcher() } } + +extension DispatchQueue { + static func ~=(_ a: DispatchQueue, _ b: DispatchQueue) -> Bool { + return a === b + } +} diff --git a/Tests/Core/DispatcherTests.swift b/Tests/Core/DispatcherTests.swift index 46d836d1d..c9cc0ee10 100644 --- a/Tests/Core/DispatcherTests.swift +++ b/Tests/Core/DispatcherTests.swift @@ -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() {