@@ -38,11 +38,13 @@ public protocol Executor: AnyObject, Sendable {
38
38
39
39
#if !$Embedded
40
40
/// `true` if this is the main executor.
41
+ @_spi ( CustomDefaultExecutors)
41
42
@available ( StdlibDeploymentTarget 6 . 2 , * )
42
43
var isMainExecutor : Bool { get }
43
44
#endif
44
45
}
45
46
47
+ @_spi ( CustomDefaultExecutors)
46
48
@available ( StdlibDeploymentTarget 6 . 2 , * )
47
49
public protocol SchedulableExecutor : Executor {
48
50
@@ -63,6 +65,7 @@ public protocol SchedulableExecutor: Executor {
63
65
/// - tolerance: The maximum additional delay permissible before the
64
66
/// job is executed. `nil` means no limit.
65
67
/// - clock: The clock used for the delay.
68
+ @_spi ( CustomDefaultExecutors)
66
69
@available ( StdlibDeploymentTarget 6 . 2 , * )
67
70
func enqueue< C: Clock > ( _ job: consuming ExecutorJob ,
68
71
after delay: C . Duration ,
@@ -83,6 +86,7 @@ public protocol SchedulableExecutor: Executor {
83
86
/// - tolerance: The maximum additional delay permissible before the
84
87
/// job is executed. `nil` means no limit.
85
88
/// - clock: The clock used for the delay..
89
+ @_spi ( CustomDefaultExecutors)
86
90
@available ( StdlibDeploymentTarget 6 . 2 , * )
87
91
func enqueue< C: Clock > ( _ job: consuming ExecutorJob ,
88
92
at instant: C . Instant ,
@@ -160,6 +164,7 @@ extension SchedulableExecutor {
160
164
161
165
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
162
166
167
+ @_spi ( CustomDefaultExecutors)
163
168
@available ( StdlibDeploymentTarget 6 . 2 , * )
164
169
public func enqueue< C: Clock > ( _ job: consuming ExecutorJob ,
165
170
after delay: C . Duration ,
@@ -171,6 +176,7 @@ extension SchedulableExecutor {
171
176
tolerance: tolerance, clock: clock)
172
177
}
173
178
179
+ @_spi ( CustomDefaultExecutors)
174
180
@available ( StdlibDeploymentTarget 6 . 2 , * )
175
181
public func enqueue< C: Clock > ( _ job: consuming ExecutorJob ,
176
182
at instant: C . Instant ,
@@ -360,6 +366,7 @@ public protocol SerialExecutor: Executor {
360
366
/// The default implementation returns `nil` is used to indicate that it is "unknown" if the current context is
361
367
/// isolated by this serial executor. The runtime then _may_ proceed to invoke `checkIsolated()` as a last-resort
362
368
/// attempt to verify the isolation of the current context.
369
+ @_spi ( CustomDefaultExecutors)
363
370
@available ( StdlibDeploymentTarget 6 . 2 , * )
364
371
func isIsolatingCurrentContext( ) -> Bool ?
365
372
@@ -369,6 +376,7 @@ public protocol SerialExecutor: Executor {
369
376
extension SerialExecutor {
370
377
371
378
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
379
+ @_spi ( CustomDefaultExecutors)
372
380
@available ( StdlibDeploymentTarget 6 . 2 , * )
373
381
public var isMainExecutor : Bool { return MainActor . executor. _isSameExecutor ( self ) }
374
382
#endif
@@ -512,9 +520,11 @@ extension SerialExecutor {
512
520
513
521
}
514
522
523
+ @_spi ( CustomDefaultExecutors)
515
524
@available ( StdlibDeploymentTarget 6 . 2 , * )
516
525
extension SerialExecutor where Self: Equatable {
517
526
527
+ @_spi ( CustomDefaultExecutors)
518
528
@available ( StdlibDeploymentTarget 6 . 2 , * )
519
529
public func isSameExclusiveExecutionContext( other: Self ) -> Bool {
520
530
return self == other
@@ -527,6 +537,7 @@ extension SerialExecutor where Self: Equatable {
527
537
/// The idea here is that some executors may work by running a loop
528
538
/// that processes events of some sort; we want a way to enter that loop,
529
539
/// and we would also like a way to trigger the loop to exit.
540
+ @_spi ( CustomDefaultExecutors)
530
541
@available ( StdlibDeploymentTarget 6 . 2 , * )
531
542
public protocol RunLoopExecutor : Executor {
532
543
/// Run the executor's run loop.
@@ -558,6 +569,7 @@ public protocol RunLoopExecutor: Executor {
558
569
func stop( )
559
570
}
560
571
572
+ @_spi ( CustomDefaultExecutors)
561
573
@available ( StdlibDeploymentTarget 6 . 2 , * )
562
574
extension RunLoopExecutor {
563
575
@@ -570,13 +582,15 @@ extension RunLoopExecutor {
570
582
571
583
/// The main executor must conform to these three protocols; we have to
572
584
/// make this a protocol for compatibility with Embedded Swift.
585
+ @_spi ( CustomDefaultExecutors)
573
586
@available ( StdlibDeploymentTarget 6 . 2 , * )
574
587
public protocol MainExecutor : RunLoopExecutor , SerialExecutor {
575
588
}
576
589
577
590
578
591
/// An ExecutorFactory is used to create the default main and task
579
592
/// executors.
593
+ @_spi ( CustomDefaultExecutors)
580
594
@available ( StdlibDeploymentTarget 6 . 2 , * )
581
595
public protocol ExecutorFactory {
582
596
#if !$Embedded
@@ -590,9 +604,11 @@ public protocol ExecutorFactory {
590
604
static var defaultExecutor : any TaskExecutor { get }
591
605
}
592
606
607
+ @_spi ( CustomDefaultExecutors)
593
608
@available ( StdlibDeploymentTarget 6 . 2 , * )
594
- typealias DefaultExecutorFactory = PlatformExecutorFactory
609
+ public typealias DefaultExecutorFactory = PlatformExecutorFactory
595
610
611
+ @_spi ( CustomDefaultExecutors)
596
612
@available ( StdlibDeploymentTarget 6 . 2 , * )
597
613
@_silgen_name ( " swift_createExecutors " )
598
614
public func _createExecutors< F: ExecutorFactory > ( factory: F . Type ) {
@@ -620,6 +636,7 @@ extension MainActor {
620
636
///
621
637
/// Attempting to set this after the first `enqueue` on the main
622
638
/// executor is a fatal error.
639
+ @_spi ( CustomDefaultExecutors)
623
640
@available ( StdlibDeploymentTarget 6 . 2 , * )
624
641
public static var executor : any MainExecutor {
625
642
// It would be good if there was a Swift way to do this
@@ -638,6 +655,7 @@ extension Task where Success == Never, Failure == Never {
638
655
///
639
656
/// Attempting to set this after the first `enqueue` on the global
640
657
/// executor is a fatal error.
658
+ @_spi ( CustomDefaultExecutors)
641
659
@available ( StdlibDeploymentTarget 6 . 2 , * )
642
660
public static var defaultExecutor : any TaskExecutor {
643
661
// It would be good if there was a Swift way to do this
@@ -658,6 +676,7 @@ extension Task where Success == Never, Failure == Never {
658
676
/// 3. The task executor for the current thread
659
677
///
660
678
/// If none of these exist, returns the default executor.
679
+ @_spi ( CustomDefaultExecutors)
661
680
@available ( StdlibDeploymentTarget 6 . 2 , * )
662
681
@_unavailableInEmbedded
663
682
public static var currentExecutor : any Executor {
@@ -672,6 +691,7 @@ extension Task where Success == Never, Failure == Never {
672
691
}
673
692
674
693
/// Get the preferred executor for the current `Task`, if any.
694
+ @_spi ( CustomDefaultExecutors)
675
695
@available ( StdlibDeploymentTarget 6 . 2 , * )
676
696
public static var preferredExecutor : ( any TaskExecutor ) ? {
677
697
if let taskExecutor = unsafe _getPreferredTaskExecutor( ) . asTaskExecutor ( ) {
@@ -684,6 +704,7 @@ extension Task where Success == Never, Failure == Never {
684
704
///
685
705
/// This follows the same logic as `currentExecutor`, except that it ignores
686
706
/// any executor that isn't a `SchedulableExecutor`.
707
+ @_spi ( CustomDefaultExecutors)
687
708
@available ( StdlibDeploymentTarget 6 . 2 , * )
688
709
@_unavailableInEmbedded
689
710
public static var currentSchedulableExecutor : ( any SchedulableExecutor ) ? {
@@ -760,6 +781,7 @@ public struct UnownedSerialExecutor: Sendable {
760
781
761
782
/// Automatically opt-in to complex equality semantics if the Executor
762
783
/// implements `Equatable`.
784
+ @_spi ( CustomDefaultExecutors)
763
785
@available ( SwiftStdlib 6 . 2 , * )
764
786
@inlinable
765
787
public init < E: SerialExecutor > ( _ executor: __shared E) {
@@ -776,6 +798,7 @@ public struct UnownedSerialExecutor: Sendable {
776
798
unsafe _executor_isComplexEquality ( self )
777
799
}
778
800
801
+ @_spi ( CustomDefaultExecutors)
779
802
@available ( StdlibDeploymentTarget 6 . 2 , * )
780
803
public func asSerialExecutor( ) -> ( any SerialExecutor ) ? {
781
804
return unsafe unsafeBitCast( executor, to: ( any SerialExecutor ) ? . self)
@@ -807,12 +830,14 @@ public struct UnownedTaskExecutor: Sendable {
807
830
unsafe self. executor = Builtin . buildOrdinaryTaskExecutorRef ( executor)
808
831
}
809
832
833
+ @_spi ( CustomDefaultExecutors)
810
834
@available ( SwiftStdlib 6 . 2 , * )
811
835
@inlinable
812
836
public init < E: TaskExecutor > ( _ executor: __shared E) {
813
837
unsafe self. executor = Builtin . buildOrdinaryTaskExecutorRef ( executor)
814
838
}
815
839
840
+ @_spi ( CustomDefaultExecutors)
816
841
@available ( StdlibDeploymentTarget 6 . 2 , * )
817
842
public func asTaskExecutor( ) -> ( any TaskExecutor ) ? {
818
843
return unsafe unsafeBitCast( executor, to: ( any TaskExecutor ) ? . self)
0 commit comments