Skip to content

Commit

Permalink
Gate OS version-specific APIs behind @available to remove platform co…
Browse files Browse the repository at this point in the history
…ntraints
  • Loading branch information
EricRabil committed Sep 1, 2022
1 parent 0b35586 commit 0b43611
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 0 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions Sources/Swexy/Combine/SubjectStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Element> {
private let subject = PassthroughSubject<Element, Never>()
private let publisher: Publishers.Share<PassthroughSubject<Element, Never>>
Expand Down
16 changes: 12 additions & 4 deletions Sources/Swexy/Utilities/ERTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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") }
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
})
}
Expand Down

0 comments on commit 0b43611

Please sign in to comment.