Skip to content

Commit

Permalink
Code formatting issues again
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienPetrilli committed Nov 7, 2023
1 parent 727b7fe commit cdf132a
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions _posts/2023-11-30-swift-concurrency-in-a-nutshell.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,16 @@ In Swift's concurrency model, a `Task` strongly retains any reference to `self`,

```swift
class MyClass {
unowned var dataStorage: DataStorage!

func refreshData() {
Task { [weak self] in
guard let self else { return } // temporarily retains self

let newData = loadDataFromDisk()
self.dataStorage = newData // Safe
unowned var dataStorage: DataStorage!

func refreshData() {
Task { [weak self] in
guard let self = self else { return } // temporarily retains self

let newData = loadDataFromDisk()
self.dataStorage = newData // Safe
}
}
}
}
```

Expand All @@ -461,16 +461,16 @@ However, introducing a suspension point can lead to issues similar to those enco

```swift
class MyClass {
unowned var dataStorage: DataStorage!

func refreshData() {
Task { [weak self] in
guard let self else { return } // temporarily retains self

let newData = await downloadData() // suspension point
self.dataStorage = newData // random crash
unowned var dataStorage: DataStorage!

func refreshData() {
Task { [weak self] in
guard let self = self else { return } // temporarily retains self

let newData = await downloadData() // suspension point
self.dataStorage = newData // random crash
}
}
}
}
```

Expand All @@ -483,15 +483,15 @@ Actor Reentrancy is a complex behavior that occurs when an actor method makes an
```swift
actor Counter {
var value = 0

func increment() {
value += 1
}

func process() async {
increment()
print(value) // 1
await doLonProcessing() // suspension point
print(value) // 1
await doLongProcessing() // suspension point
print(value) // Unpredictable output (1?)
}
}
Expand Down

0 comments on commit cdf132a

Please sign in to comment.