From cdf132ad73d4f1c6f9fc40628b4370a7386c707e Mon Sep 17 00:00:00 2001 From: dpetrilli-externe Date: Tue, 7 Nov 2023 12:01:31 +0100 Subject: [PATCH] Code formatting issues again --- ...3-11-30-swift-concurrency-in-a-nutshell.md | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/_posts/2023-11-30-swift-concurrency-in-a-nutshell.md b/_posts/2023-11-30-swift-concurrency-in-a-nutshell.md index 46ea54f70..6d9d45f7f 100644 --- a/_posts/2023-11-30-swift-concurrency-in-a-nutshell.md +++ b/_posts/2023-11-30-swift-concurrency-in-a-nutshell.md @@ -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 + } } - } } ``` @@ -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 + } } - } } ``` @@ -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?) } }