From 1f651932120a82754b7f2036618a8b7d3a67e49d Mon Sep 17 00:00:00 2001 From: Caleb Kleveter Date: Wed, 22 Jan 2020 12:27:35 -0600 Subject: [PATCH] Only add Combine support if module can be imported --- .../SwiftCoroutine/Combine/CoFuture+Combine.swift | 2 ++ .../Combine/CoPromise+Combine.swift | 2 ++ .../SwiftCoroutine/Combine/CoSubscription.swift | 2 ++ .../Combine/Dispatcher+Scheduler.swift | 2 ++ .../Combine/Publisher+Extensions.swift | 2 ++ .../SwiftCoroutine/Protocols/CoCancellable.swift | 15 ++++++++++++++- Tests/SwiftCoroutineTests/CombineTests.swift | 2 ++ 7 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftCoroutine/Combine/CoFuture+Combine.swift b/Sources/SwiftCoroutine/Combine/CoFuture+Combine.swift index a656b34..d0965d7 100644 --- a/Sources/SwiftCoroutine/Combine/CoFuture+Combine.swift +++ b/Sources/SwiftCoroutine/Combine/CoFuture+Combine.swift @@ -6,6 +6,7 @@ // Copyright © 2019 Alex Belozierov. All rights reserved. // +#if canImport(Combine) import Combine @available(OSX 10.15, iOS 13.0, *) @@ -35,3 +36,4 @@ extension Subscriber { } } +#endif diff --git a/Sources/SwiftCoroutine/Combine/CoPromise+Combine.swift b/Sources/SwiftCoroutine/Combine/CoPromise+Combine.swift index bba6333..104c379 100644 --- a/Sources/SwiftCoroutine/Combine/CoPromise+Combine.swift +++ b/Sources/SwiftCoroutine/Combine/CoPromise+Combine.swift @@ -6,6 +6,7 @@ // Copyright © 2019 Alex Belozierov. All rights reserved. // +#if canImport(Combine) import Combine @available(OSX 10.15, iOS 13.0, *) @@ -23,3 +24,4 @@ extension CoPromise: Subject { } } +#endif diff --git a/Sources/SwiftCoroutine/Combine/CoSubscription.swift b/Sources/SwiftCoroutine/Combine/CoSubscription.swift index fd74be3..04b0a86 100644 --- a/Sources/SwiftCoroutine/Combine/CoSubscription.swift +++ b/Sources/SwiftCoroutine/Combine/CoSubscription.swift @@ -6,6 +6,7 @@ // Copyright © 2019 Alex Belozierov. All rights reserved. // +#if canImport(Combine) import Combine @available(OSX 10.15, iOS 13.0, *) @@ -38,3 +39,4 @@ extension CoSubscription: Hashable { } } +#endif diff --git a/Sources/SwiftCoroutine/Combine/Dispatcher+Scheduler.swift b/Sources/SwiftCoroutine/Combine/Dispatcher+Scheduler.swift index d070299..dd4d3d0 100644 --- a/Sources/SwiftCoroutine/Combine/Dispatcher+Scheduler.swift +++ b/Sources/SwiftCoroutine/Combine/Dispatcher+Scheduler.swift @@ -6,6 +6,7 @@ // Copyright © 2019 Alex Belozierov. All rights reserved. // +#if canImport(Combine) import Combine @available(OSX 10.15, iOS 13.0, *) @@ -20,3 +21,4 @@ extension Coroutine.Dispatcher { } } +#endif diff --git a/Sources/SwiftCoroutine/Combine/Publisher+Extensions.swift b/Sources/SwiftCoroutine/Combine/Publisher+Extensions.swift index 71467ff..9f0a714 100644 --- a/Sources/SwiftCoroutine/Combine/Publisher+Extensions.swift +++ b/Sources/SwiftCoroutine/Combine/Publisher+Extensions.swift @@ -6,6 +6,7 @@ // Copyright © 2019 Alex Belozierov. All rights reserved. // +#if canImport(Combine) import Combine import Dispatch @@ -26,3 +27,4 @@ extension Publisher { } } +#endif diff --git a/Sources/SwiftCoroutine/Protocols/CoCancellable.swift b/Sources/SwiftCoroutine/Protocols/CoCancellable.swift index ae8b6af..9854f9f 100644 --- a/Sources/SwiftCoroutine/Protocols/CoCancellable.swift +++ b/Sources/SwiftCoroutine/Protocols/CoCancellable.swift @@ -6,6 +6,8 @@ // Copyright © 2020 Alex Belozierov. All rights reserved. // +#if !canImport(Combine) + import Combine public protocol CoCancellable: Cancellable, Hashable { @@ -15,6 +17,17 @@ public protocol CoCancellable: Cancellable, Hashable { } +#else + +public protocol CoCancellable: Hashable { + + func cancel() + func cancelUpstream() + +} + +#endif + extension CoCancellable where Self: AnyObject { @inlinable public var anyCoCancellable: AnyCoCancellable { @@ -47,5 +60,5 @@ final public class AnyCoCancellable: CoCancellable { @inlinable public func hash(into hasher: inout Hasher) { ObjectIdentifier(self).hash(into: &hasher) } - + } diff --git a/Tests/SwiftCoroutineTests/CombineTests.swift b/Tests/SwiftCoroutineTests/CombineTests.swift index 4f44ec9..20a3394 100644 --- a/Tests/SwiftCoroutineTests/CombineTests.swift +++ b/Tests/SwiftCoroutineTests/CombineTests.swift @@ -6,6 +6,7 @@ // Copyright © 2019 Alex Belozierov. All rights reserved. // +#if canImport(Combine) import XCTest import Combine import SwiftCoroutine @@ -35,3 +36,4 @@ class CombineTests: XCTestCase { } } +#endif