Skip to content

Rework availability for executor to avoid warnings #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/AsyncSequenceValidation/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
47 changes: 42 additions & 5 deletions Sources/AsyncSequenceValidation/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down