@@ -1842,8 +1842,7 @@ Task {
18421842 ```
18431843-->
18441844
1845- Use task groups and tasks to structure concurrent code.
1846- Writing ` async ` -` let ` implicitly creates a task.
1845+ Use task groups to structure concurrent code.
18471846
18481847``` swift
18491848let userIDs = await withTaskGroup (of : Int .self ) { taskGroup in
@@ -1863,15 +1862,17 @@ let userIDs = await withTaskGroup(of: Int.self) { taskGroup in
18631862
18641863Actors are similar to classes,
18651864except they ensure that different asynchronous functions
1866- can all interact with an instance of the same actor at the same time.
1865+ can safely interact with an instance of the same actor at the same time.
18671866
18681867``` swift
1869- actor Oven {
1870- private var contents: [String ] = []
1871- func bake (_ food : String ) -> String {
1872- contents.append (food)
1873- // ... wait for food to bake ...
1874- return contents.removeLast ()
1868+ actor ServerConnection {
1869+ var server: String = " primary"
1870+ private var activeUsers: [Int ] = []
1871+ func connect () async -> Int {
1872+ let userID = await fetchUserID (from : server)
1873+ // ... communicate with server ...
1874+ activeUsers.append (userID)
1875+ return userID
18751876 }
18761877}
18771878```
@@ -1897,8 +1898,8 @@ to indicate that it might have to wait for other code
18971898that's already running on the actor to finish.
18981899
18991900``` swift
1900- let oven = Oven ()
1901- let biscuits = await oven. bake ( " biscuits " )
1901+ let server = ServerConnection ()
1902+ let userID = await server. connect ( )
19021903```
19031904
19041905<!--
0 commit comments