@@ -22,6 +22,25 @@ import Swift
2222/// such a declaration from another actor (or from nonisolated code),
2323/// synchronization is performed through the shared actor instance to ensure
2424/// mutually-exclusive access to the declaration.
25+ ///
26+ /// ## Custom Actor Executors
27+ /// A global actor use a custom executor if it needs to customize its execution
28+ /// semantics, for example, by making sure all of its invocations are run on a
29+ /// specific thread or dispatch queue.
30+ ///
31+ /// This is done the same way as with normal non-global actors, by declaring a
32+ /// ``Actor/unownedExecutor`` nonisolated property in the ``ActorType``
33+ /// underlying this global actor.
34+ ///
35+ /// It is *not* necessary to override the ``sharedUnownedExecutor`` static
36+ /// property of the global actor, as its default implementation already
37+ /// delegates to the ``shared.unownedExecutor``, which is the most reasonable
38+ /// and correct implementation of this protocol requirement.
39+ ///
40+ /// You can find out more about custom executors, by referring to the
41+ /// ``SerialExecutor`` protocol's documentation.
42+ ///
43+ /// - SeeAlso: ``SerialExecutor``
2544@available ( SwiftStdlib 5 . 1 , * )
2645public protocol GlobalActor {
2746 /// The type of the shared actor instance that will be used to provide
@@ -36,10 +55,22 @@ public protocol GlobalActor {
3655 /// instance.
3756 static var shared : ActorType { get }
3857
39- /// The shared executor instance that will be used to provide
40- /// mutually-exclusive access for the global actor.
58+ /// Shorthand for referring to the `shared.unownedExecutor` of this global actor.
59+ ///
60+ /// When declaring a global actor with a custom executor, prefer to implement
61+ /// the underlying actor's ``Actor/unownedExecutor`` property, and leave this
62+ /// `sharedUnownedExecutor` default implementation in-place as it will simply
63+ /// delegate to the `shared.unownedExecutor`.
64+ ///
65+ /// The value of this property must be equivalent to `shared.unownedExecutor`,
66+ /// as may be used by the Swift concurrency runtime or explicit user code. with
67+ /// that assumption in mind.
68+ ///
69+ /// Returning different executors for different invocations of this computed
70+ /// property is also illegal, as it could lead to inconsistent synchronization
71+ /// of the underlying actor.
4172 ///
42- /// The value of this property must be equivalent to `shared.unownedExecutor`.
73+ /// - SeeAlso: ``SerialExecutor``
4374 static var sharedUnownedExecutor : UnownedSerialExecutor { get }
4475}
4576
0 commit comments