@@ -6,6 +6,44 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
6
6
Swift 5.5
7
7
---------
8
8
9
+ * [ SE-0313] [ ] :
10
+
11
+ A type can be defined as a global actor. Global actors extend the notion
12
+ of actor isolation outside of a single actor type, so that global state
13
+ (and the functions that access it) can benefit from actor isolation,
14
+ even if the state and functions are scattered across many different
15
+ types, functions and modules. Global actors make it possible to safely
16
+ work with global variables in a concurrent program, as well as modeling
17
+ other global program constraints such as code that must only execute on
18
+ the "main thread" or "UI thread". A new global actor can be defined with
19
+ the ` globalActor ` attribute:
20
+
21
+ ``` swift
22
+ @globalActor
23
+ struct DatabaseActor {
24
+ actor ActorType { }
25
+
26
+ static let shared: ActorType = ActorType ()
27
+ }
28
+ ```
29
+
30
+ Global actor types can be used as custom attributes on various declarations,
31
+ which ensures that those declarations are only accessed on the actor described
32
+ by the global actor's ` shared ` instance. For example:
33
+
34
+ ``` swift
35
+ @DatabaseActor func queryDB (query : Query) throws -> QueryResult
36
+
37
+ func runQuery (queryString : String ) async throws -> QueryResult {
38
+ let query = try Query (parsing : queryString)
39
+ return try await queryDB (query : query) // 'await' because this implicitly hops to DatabaseActor.shared
40
+ }
41
+ ```
42
+
43
+ The concurrency library defines one global actor, ` MainActor ` , which
44
+ represents the main thread of execution. It should be used for any code that
45
+ must execute on the main thread, e.g., for updating UI.
46
+
9
47
* [ SE-0313] [ ] :
10
48
11
49
Declarations inside an actor that would normally be actor-isolated can
@@ -8525,6 +8563,7 @@ Swift 1.0
8525
8563
[SE- 0306 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
8526
8564
[SE- 0310 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
8527
8565
[SE- 0313 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
8566
+ [SE- 0316 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
8528
8567
8529
8568
[SR- 75 ]: < https: // bugs.swift.org/browse/SR-75>
8530
8569
[SR- 106 ]: < https: // bugs.swift.org/browse/SR-106>
0 commit comments