Skip to content

Commit

Permalink
Remove #available and @available checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lickel committed Dec 20, 2022
1 parent eb87f45 commit eb10eec
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 195 deletions.
21 changes: 10 additions & 11 deletions Sources/Scheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public final class UIScheduler: Scheduler {
/// be equal.
private final class DispatchSourceTimerWrapper: Hashable {
private let value: DispatchSourceTimer

#if swift(>=4.1.50)
fileprivate func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self))
Expand All @@ -307,11 +307,11 @@ private final class DispatchSourceTimerWrapper: Hashable {
return ObjectIdentifier(self).hashValue
}
#endif

fileprivate init(_ value: DispatchSourceTimer) {
self.value = value
}

fileprivate static func ==(lhs: DispatchSourceTimerWrapper, rhs: DispatchSourceTimerWrapper) -> Bool {
// Note that this isn't infinite recursion thanks to `===`.
return lhs === rhs
Expand All @@ -324,7 +324,7 @@ public final class QueueScheduler: DateScheduler {
/// queue.
///
/// - note: Unlike `UIScheduler`, this scheduler supports scheduling for a
/// future date, and will always schedule asynchronously (even if
/// future date, and will always schedule asynchronously (even if
/// already running on the main thread).
public static let main = QueueScheduler(internalQueue: DispatchQueue.main)

Expand All @@ -333,9 +333,9 @@ public final class QueueScheduler: DateScheduler {
}

public let queue: DispatchQueue

private var timers: Atomic<Set<DispatchSourceTimerWrapper>>

internal init(internalQueue: DispatchQueue) {
queue = internalQueue
timers = Atomic(Set())
Expand All @@ -362,7 +362,6 @@ public final class QueueScheduler: DateScheduler {
/// - name: A name for the queue in the form of reverse domain.
/// - targeting: (Optional) The queue on which this scheduler's work is
/// targeted
@available(OSX 10.10, *)
public convenience init(
qos: DispatchQoS = .default,
name: String = "org.reactivecocoa.ReactiveSwift.QueueScheduler",
Expand Down Expand Up @@ -434,8 +433,8 @@ public final class QueueScheduler: DateScheduler {
/// - interval: A repetition interval.
/// - action: Closure of the action to repeat.
///
/// - note: If you plan to specify an `interval` value greater than 200,000
/// seconds, use `schedule(after:interval:leeway:action)` instead
/// - note: If you plan to specify an `interval` value greater than 200,000
/// seconds, use `schedule(after:interval:leeway:action)` instead
/// and specify your own `leeway` value to avoid potential overflow.
///
/// - returns: Optional disposable that can be used to cancel the work
Expand Down Expand Up @@ -485,14 +484,14 @@ public final class QueueScheduler: DateScheduler {
timer.resume()

let wrappedTimer = DispatchSourceTimerWrapper(timer)

timers.modify { timers in
timers.insert(wrappedTimer)
}

return AnyDisposable { [weak self] in
timer.cancel()

if let scheduler = self {
scheduler.timers.modify { timers in
timers.remove(wrappedTimer)
Expand Down
26 changes: 12 additions & 14 deletions Tests/ReactiveSwiftTests/ActionSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,22 @@ class ActionSpec: QuickSpec {
action1.apply().start()
}

if #available(macOS 10.10, *) {
it("should not loop indefinitely") {
let condition = MutableProperty(1)
it("should not loop indefinitely") {
let condition = MutableProperty(1)

let action = Action<Void, Void, Never>(state: condition, enabledIf: { $0 == 0 }) { _, _ in
return .empty
}
let action = Action<Void, Void, Never>(state: condition, enabledIf: { $0 == 0 }) { _, _ in
return .empty
}

var count = 0
var count = 0

action.isExecuting.producer
.startWithValues { _ in
condition.value = 10
action.isExecuting.producer
.startWithValues { _ in
condition.value = 10

count += 1
expect(count) == 1
}
}
count += 1
expect(count) == 1
}
}

describe("completed") {
Expand Down
8 changes: 1 addition & 7 deletions Tests/ReactiveSwiftTests/PropertySpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,7 @@ class PropertySpec: QuickSpec {
}

it("should not deadlock") {
let queue: DispatchQueue

if #available(macOS 10.10, *) {
queue = DispatchQueue.global(qos: .userInteractive)
} else {
queue = DispatchQueue.global(priority: .high)
}
let queue = DispatchQueue.global(qos: .userInteractive)

let setup = DispatchGroup()
let workers = DispatchGroup()
Expand Down
8 changes: 0 additions & 8 deletions Tests/ReactiveSwiftTests/QueueScheduler+Factory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ extension QueueScheduler {
let file = URL(string: file)?.lastPathComponent ?? "<unknown>"
let label = "reactiveswift:\(file):\(line)"

#if targetEnvironment(macCatalyst)
return QueueScheduler(name: label)
#else
if #available(OSX 10.10, iOS 8.0, *) {
return QueueScheduler(name: label)
} else {
return QueueScheduler()
}
#endif
}
}
7 changes: 1 addition & 6 deletions Tests/ReactiveSwiftTests/SchedulerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ class SchedulerSpec: QuickSpec {
func dispatchSyncInBackground(_ action: @escaping () -> Void) {
let group = DispatchGroup()

let globalQueue: DispatchQueue
if #available(*, OSX 10.10) {
globalQueue = DispatchQueue.global()
} else {
globalQueue = DispatchQueue.global(priority: .default)
}
let globalQueue = DispatchQueue.global()

globalQueue.async(group: group, execute: action)
group.wait()
Expand Down
14 changes: 2 additions & 12 deletions Tests/ReactiveSwiftTests/SignalProducerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3088,12 +3088,7 @@ class SignalProducerSpec: QuickSpec {

let group = DispatchGroup()

let globalQueue: DispatchQueue
if #available(*, OSX 10.10) {
globalQueue = DispatchQueue.global()
} else {
globalQueue = DispatchQueue.global(priority: .default)
}
let globalQueue = DispatchQueue.global()

globalQueue.async(group: group, flags: []) {
result = producer.last()
Expand Down Expand Up @@ -3136,12 +3131,7 @@ class SignalProducerSpec: QuickSpec {

let group = DispatchGroup()

let globalQueue: DispatchQueue
if #available(*, OSX 10.10) {
globalQueue = DispatchQueue.global()
} else {
globalQueue = DispatchQueue.global(priority: .default)
}
let globalQueue = DispatchQueue.global()

globalQueue.async(group: group, flags: []) {
result = producer.wait()
Expand Down
Loading

0 comments on commit eb10eec

Please sign in to comment.