Skip to content

Commit 4a1fb99

Browse files
authored
Rework availability for executor to avoid warnings (apple#288)
1 parent b0ec469 commit 4a1fb99

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

Sources/AsyncSequenceValidation/Job.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ struct Job: Hashable, @unchecked Sendable {
1919
}
2020

2121
func execute() {
22-
_swiftJobRun(unsafeBitCast(job, to: UnownedJob.self), AsyncSequenceValidationDiagram.Context.executor.asUnownedSerialExecutor())
22+
_swiftJobRun(unsafeBitCast(job, to: UnownedJob.self), AsyncSequenceValidationDiagram.Context.unownedExecutor)
2323
}
2424
}

Sources/AsyncSequenceValidation/Test.swift

+42-5
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,62 @@ extension AsyncSequenceValidationDiagram {
6767
}
6868

6969
struct Context {
70+
#if swift(<5.9)
7071
final class ClockExecutor: SerialExecutor {
71-
@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
72+
func enqueue(_ job: UnownedJob) {
73+
job._runSynchronously(on: self.asUnownedSerialExecutor())
74+
}
75+
76+
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
77+
UnownedSerialExecutor(ordinary: self)
78+
}
79+
}
80+
81+
private static let _executor = ClockExecutor()
82+
83+
static var unownedExecutor: UnownedSerialExecutor {
84+
_executor.asUnownedSerialExecutor()
85+
}
86+
#else
87+
@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
88+
final class ClockExecutor_5_9: SerialExecutor {
7289
func enqueue(_ job: __owned ExecutorJob) {
7390
job.runSynchronously(on: asUnownedSerialExecutor())
7491
}
7592

76-
@available(*, deprecated) // known deprecation warning
93+
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
94+
UnownedSerialExecutor(ordinary: self)
95+
}
96+
}
97+
98+
final class ClockExecutor_Pre5_9: SerialExecutor {
99+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
100+
@available(*, deprecated, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead")
77101
func enqueue(_ job: UnownedJob) {
78-
job._runSynchronously(on: asUnownedSerialExecutor())
102+
job._runSynchronously(on: self.asUnownedSerialExecutor())
79103
}
80-
104+
81105
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
82106
UnownedSerialExecutor(ordinary: self)
83107
}
84108
}
85109

110+
private static let _executor: AnyObject = {
111+
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
112+
return ClockExecutor_5_9()
113+
} else {
114+
return ClockExecutor_Pre5_9()
115+
}
116+
}()
117+
118+
static var unownedExecutor: UnownedSerialExecutor {
119+
(_executor as! any SerialExecutor).asUnownedSerialExecutor()
120+
}
121+
#endif
122+
86123
static var clock: Clock?
87124

88-
static let executor = ClockExecutor()
125+
89126

90127
static var driver: TaskDriver?
91128

0 commit comments

Comments
 (0)