From 0b436118d31e7eb35dbd51bfe8866ac76fdf6943 Mon Sep 17 00:00:00 2001 From: Eric Rabil Date: Thu, 1 Sep 2022 15:31:52 -0400 Subject: [PATCH] Gate OS version-specific APIs behind @available to remove platform contraints --- Package.swift | 3 --- Sources/Swexy/Combine/SubjectStream.swift | 1 + Sources/Swexy/Utilities/ERTimer.swift | 16 ++++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Package.swift b/Package.swift index daa1b4b..d9b5d11 100644 --- a/Package.swift +++ b/Package.swift @@ -5,9 +5,6 @@ import PackageDescription let package = Package( name: "Swexy", - platforms: [ - .iOS(.v13), .macOS(.v10_15), .tvOS(.v13), .watchOS(.v6) - ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( diff --git a/Sources/Swexy/Combine/SubjectStream.swift b/Sources/Swexy/Combine/SubjectStream.swift index 8f8fe82..809459d 100644 --- a/Sources/Swexy/Combine/SubjectStream.swift +++ b/Sources/Swexy/Combine/SubjectStream.swift @@ -12,6 +12,7 @@ import Combine @_silgen_name("dispatch_get_current_queue") func dispatch_get_current_queue() -> DispatchQueue +@available(macOS 10.15, *) public class SubjectStream { private let subject = PassthroughSubject() private let publisher: Publishers.Share> diff --git a/Sources/Swexy/Utilities/ERTimer.swift b/Sources/Swexy/Utilities/ERTimer.swift index 10bf19b..221803c 100644 --- a/Sources/Swexy/Utilities/ERTimer.swift +++ b/Sources/Swexy/Utilities/ERTimer.swift @@ -11,6 +11,7 @@ import Combine import Swog #endif +@available(macOS 10.15, *) public class ERTimer { #if DEBUG && canImport(Swog) public static let log = Logger(category: "ERTimer") @@ -50,6 +51,7 @@ public class ERTimer { } } +@available(macOS 10.15, *) public class ERControllableTimer: ERTimer { #if DEBUG && canImport(Swog) public override var log: Swog.Logger { .init(category: "ERControllableTimer") } @@ -93,6 +95,7 @@ public class ERControllableTimer: ERTimer { } } +@available(macOS 10.15, *) public class ERExponentialTimer { #if DEBUG && canImport(Swog) public static let log = Logger(category: "ERExponentialTimer") @@ -132,17 +135,22 @@ public class ERExponentialTimer { } } - public init(base: DispatchTimeInterval, queue: DispatchQueue = .global(qos: .utility), growthRate: Double = 1.0, callback: @escaping () -> Bool) { + + public convenience init(base: DispatchTimeInterval, queue: DispatchQueue = .global(qos: .utility), growthRate: Double = 1.0, callback: @escaping () -> Bool) { + self.init(base: base, queue: queue, growthRate: growthRate, callback: { _ in callback() }) + } + + public init(base: DispatchTimeInterval, queue: DispatchQueue = .global(qos: .utility), growthRate: Double = 1.0, callback: @escaping (ERExponentialTimer) -> Bool) { self.base = base self.growthRate = growthRate - timer = ERTimer(scheduledFromNow: base, queue: queue, callback: { + timer = ERTimer(scheduledFromNow: base, queue: queue, callback: { [weak timer] in let attempts = self.attempts + 1 #if DEBUG && canImport(Swog) self.log.info("Incrementing attempts to \(attempts)") #endif self.attempts = attempts - if callback() { - self.timer!.reschedule(fromNow: self.waitPeriod) + if callback(self) { + timer?.reschedule(fromNow: self.waitPeriod) } }) }