@@ -28,11 +28,58 @@ internal func _swiftJobRun(_ job: UnownedJob,
2828public struct UnownedJob: Sendable {
2929 private var context : Builtin . Job
3030
31+ /// The priority of this job.
32+ @available ( SwiftStdlib 5 . 9 , * )
33+ public var priority : JobPriority {
34+ let raw = _swift_concurrency_jobPriority ( self )
35+ return JobPriority ( rawValue: raw)
36+ }
37+
3138 @_alwaysEmitIntoClient
3239 @inlinable
40+ @available ( * , deprecated, renamed: " runSynchronously " )
3341 public func _runSynchronously( on executor: UnownedSerialExecutor ) {
3442 _swiftJobRun ( self , executor)
3543 }
44+
45+ @_alwaysEmitIntoClient
46+ @inlinable
47+ public func runSynchronously( on executor: UnownedSerialExecutor ) {
48+ _swiftJobRun ( self , executor)
49+ }
50+ }
51+
52+ /// The priority of this job.
53+ ///
54+ /// The executor determines how priority information affects the way tasks are scheduled.
55+ /// The behavior varies depending on the executor currently being used.
56+ /// Typically, executors attempt to run tasks with a higher priority
57+ /// before tasks with a lower priority.
58+ /// However, the semantics of how priority is treated are left up to each
59+ /// platform and `Executor` implementation.
60+ ///
61+ /// A Job's priority is roughly equivalent to a `TaskPriority`,
62+ /// however, since not all jobs are tasks, represented as separate type.
63+ ///
64+ /// Conversions between the two priorities are available as initializers on the respective types.
65+ @available ( SwiftStdlib 5 . 9 , * )
66+ public struct JobPriority {
67+ public typealias RawValue = UInt8
68+
69+ /// The raw priority value.
70+ public var rawValue : RawValue
71+ }
72+
73+ @available ( SwiftStdlib 5 . 9 , * )
74+ extension TaskPriority {
75+ /// Convert a job priority to a task priority.
76+ ///
77+ /// Most values are directly interchangeable, but this initializer reserves the right to fail for certain values.
78+ @available ( SwiftStdlib 5 . 9 , * )
79+ public init ? ( _ p: JobPriority ) {
80+ // currently we always convert, but we could consider mapping over only recognized values etc.
81+ self = . init( rawValue: p. rawValue)
82+ }
3683}
3784
3885/// A mechanism to interface
@@ -291,3 +338,7 @@ public func withUnsafeThrowingContinuation<T>(
291338public func _abiEnableAwaitContinuation( ) {
292339 fatalError ( " never use this function " )
293340}
341+
342+ @available ( SwiftStdlib 5 . 9 , * )
343+ @_silgen_name ( " swift_concurrency_jobPriority " )
344+ internal func _swift_concurrency_jobPriority( _ job: UnownedJob ) -> UInt8
0 commit comments