From 37c3f962e0d21c7ab029f07c2dfd83c083d40d0d Mon Sep 17 00:00:00 2001 From: Philippe Hausler Date: Fri, 18 Aug 2023 12:30:00 -0700 Subject: [PATCH] Rework availability for executor to avoid warnings --- Sources/AsyncSequenceValidation/Job.swift | 2 +- Sources/AsyncSequenceValidation/Test.swift | 47 +++++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Sources/AsyncSequenceValidation/Job.swift b/Sources/AsyncSequenceValidation/Job.swift index 44dedbc8..461af50d 100644 --- a/Sources/AsyncSequenceValidation/Job.swift +++ b/Sources/AsyncSequenceValidation/Job.swift @@ -19,6 +19,6 @@ struct Job: Hashable, @unchecked Sendable { } func execute() { - _swiftJobRun(unsafeBitCast(job, to: UnownedJob.self), AsyncSequenceValidationDiagram.Context.executor.asUnownedSerialExecutor()) + _swiftJobRun(unsafeBitCast(job, to: UnownedJob.self), AsyncSequenceValidationDiagram.Context.unownedExecutor) } } diff --git a/Sources/AsyncSequenceValidation/Test.swift b/Sources/AsyncSequenceValidation/Test.swift index 0275cc11..8dc86832 100644 --- a/Sources/AsyncSequenceValidation/Test.swift +++ b/Sources/AsyncSequenceValidation/Test.swift @@ -67,25 +67,62 @@ extension AsyncSequenceValidationDiagram { } struct Context { +#if swift(<5.9) final class ClockExecutor: SerialExecutor { - @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) + func enqueue(_ job: UnownedJob) { + job._runSynchronously(on: self.asUnownedSerialExecutor()) + } + + func asUnownedSerialExecutor() -> UnownedSerialExecutor { + UnownedSerialExecutor(ordinary: self) + } + } + + private static let _executor = ClockExecutor() + + static var unownedExecutor: UnownedSerialExecutor { + _executor.asUnownedSerialExecutor() + } +#else + @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) + final class ClockExecutor_5_9: SerialExecutor { func enqueue(_ job: __owned ExecutorJob) { job.runSynchronously(on: asUnownedSerialExecutor()) } - @available(*, deprecated) // known deprecation warning + func asUnownedSerialExecutor() -> UnownedSerialExecutor { + UnownedSerialExecutor(ordinary: self) + } + } + + final class ClockExecutor_Pre5_9: SerialExecutor { + @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) + @available(*, deprecated, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead") func enqueue(_ job: UnownedJob) { - job._runSynchronously(on: asUnownedSerialExecutor()) + job._runSynchronously(on: self.asUnownedSerialExecutor()) } - + func asUnownedSerialExecutor() -> UnownedSerialExecutor { UnownedSerialExecutor(ordinary: self) } } + private static let _executor: AnyObject = { + if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) { + return ClockExecutor_5_9() + } else { + return ClockExecutor_Pre5_9() + } + }() + + static var unownedExecutor: UnownedSerialExecutor { + (_executor as! any SerialExecutor).asUnownedSerialExecutor() + } +#endif + static var clock: Clock? - static let executor = ClockExecutor() + static var driver: TaskDriver?