@@ -16,9 +16,8 @@ for example, a computer with a four-core processor
1616can run four pieces of code at the same time,
1717with each core carrying out one of the tasks.
1818A program that uses parallel and asynchronous code
19- carries out multiple operations at a time;
20- it suspends operations that are waiting for an external system,
21- and makes it easier to write this code in a memory-safe way.
19+ carries out multiple operations at a time,
20+ and it suspends operations that are waiting for an external system.
2221
2322The additional scheduling flexibility from parallel or asynchronous code
2423also comes with a cost of increased complexity.
@@ -345,6 +344,14 @@ so you can call it from synchronous code and wait for the result.
345344The Swift standard library intentionally omits this unsafe functionality,
346345and trying to implement it yourself can lead to
347346problems like subtle races, threading issues, and deadlocks.
347+ When adding concurrent code to an existing project,
348+ work from the top down.
349+ Specifically,
350+ start by converting the topmost layer of code to use concurrency,
351+ and then start converting the functions and methods that it calls,
352+ working through the project's architecture one layer at a time.
353+ There's no way to take a bottom-up approach,
354+ because synchronous code can't ever call asynchronous code.
348355
349356<!--
350357 OUTLINE
@@ -655,7 +662,7 @@ Each task checks whether it has been canceled
655662at the appropriate points in its execution,
656663and responds to cancellation an appropriate way.
657664Depending on the work you're doing,
658- that usually means one of the following:
665+ responding to cancellation usually means one of the following:
659666
660667- Throwing an error like ` CancellationError `
661668- Returning ` nil ` or an empty collection
@@ -1044,7 +1051,7 @@ only code running on an actor can access that actor's local state.
10441051This guarantee is known as * actor isolation* .
10451052
10461053The following aspects of the Swift concurrency model
1047- combine to make it easier to reason about shared mutable state:
1054+ work together to make it easier to reason about shared mutable state:
10481055
10491056- Code in between possible suspension points runs sequentially,
10501057 without the possibility of interruption from other concurrent code.
@@ -1071,7 +1078,7 @@ extension TemperatureLogger {
10711078}
10721079```
10731080
1074- The code above converts one measurement at a time.
1081+ The code above converts the array of measurements, one at a time.
10751082While the map operation is in progress,
10761083some temperatures are in Fahrenheit and others are in Celsius.
10771084However, because none of the code includes ` await ` ,
@@ -1083,8 +1090,10 @@ This means there's no way for other code
10831090to read a list of partially converted temperatures
10841091while unit conversion is in progress.
10851092
1086- The ` convertFarenheitToCelsius() ` method makes an even stronger guarantee:
1087- It's a synchronous method,
1093+ In addition to writing code in an actor
1094+ that protects temporary invalid state by omitting potential suspension points,
1095+ you can move that code into a synchronous method.
1096+ The ` convertFarenheitToCelsius() ` method above is method,
10881097so it's guaranteed to * never* contain potential suspension points.
10891098This function encapsulates the code
10901099that temporarily makes the data model inconsistent,
0 commit comments