|
3 | 3 | * Proposal: [SE-0475](0475-observed.md)
|
4 | 4 | * Authors: [Philippe Hausler](https://github.com/phausler)
|
5 | 5 | * Review Manager: [Freddy Kellison-Linn](https://github.com/Jumhyn)
|
6 |
| -* Status: **Active Review (April 10 ... May 13, 2025)** |
| 6 | +* Status: **Accepted** |
7 | 7 | * Implementation: https://github.com/swiftlang/swift/pull/79817
|
8 |
| -* Review: ([pitch](https://forums.swift.org/t/pitch-transactional-observation-of-values/78315)) ([review](https://forums.swift.org/t/se-0475-transactional-observation-of-values/79224)) |
| 8 | +* Review: ([pitch](https://forums.swift.org/t/pitch-transactional-observation-of-values/78315)) ([review](https://forums.swift.org/t/se-0475-transactional-observation-of-values/79224)) ([acceptance](https://forums.swift.org/t/accepted-se-0475-transactional-observation-of-values/80389)) |
9 | 9 |
|
10 | 10 | ## Introduction
|
11 | 11 |
|
@@ -103,7 +103,7 @@ that pet's name.
|
103 | 103 |
|
104 | 104 | ## Detailed design
|
105 | 105 |
|
106 |
| -There a few behaviors that are prerequisites to understanding the requirements |
| 106 | +There are a few behaviors that are prerequisites to understanding the requirements |
107 | 107 | of the actual design. These two key behaviors are how the model handles tearing
|
108 | 108 | and how the model handles sharing.
|
109 | 109 |
|
@@ -173,7 +173,7 @@ Task.detached {
|
173 | 173 | }
|
174 | 174 | ```
|
175 | 175 |
|
176 |
| -In this case both tasks will get the same values upon the same events. This can |
| 176 | +In this case both tasks will get consistently safe accessed values. This can |
177 | 177 | be achieved without needing an extra buffer since the suspension of each side of
|
178 | 178 | the iteration are continuations resuming all together upon the accessor's
|
179 | 179 | execution on the specified isolation. This facilitates subject-like behavior
|
@@ -257,6 +257,12 @@ composition of potentially failable systems. Any thrown error will mean that the
|
257 | 257 | terminate with that given failure. Subsequent calls then to `next` on those
|
258 | 258 | iterators will return `nil` - indicating that the iteration is complete.
|
259 | 259 |
|
| 260 | +The type `Observations` will conform to `AsyncSequence`. This means that it |
| 261 | +adheres to the cancellation behavior of other `AsyncSequence` types; if the task |
| 262 | +is cancelled then the iterator will return nil, and any time it becomes |
| 263 | +terminal for any reason that sequence will remain terminal and continue returning nil. |
| 264 | +Termination by cancellation however is independent for each instance. |
| 265 | + |
260 | 266 | ## Behavioral Notes
|
261 | 267 |
|
262 | 268 | There are a number of scenarios of iteration that can occur. These can range from production rate to iteration rate differentials to isolation differentials to concurrent iterations. Enumerating all possible combinations is of course not possible but the following explanations should illustrate some key usages. `Observations` does not make unsafe code somehow safe - the concepts of isolation protection or exclusive access are expected to be brought to the table by the types involved. It does however require the enforcements via Swift Concurrency particularly around the marking of the types and closures being required to be `Sendable`. The following examples will only illustrate well behaved types and avoid fully unsafe behavior that would lead to crashes because the types being used are circumventing that language safety.
|
@@ -351,7 +357,7 @@ The result of the observation may print the following output, but the primary pr
|
351 | 357 | 3 3
|
352 | 358 | ```
|
353 | 359 |
|
354 |
| -This case dropped the last value of the iteration because the accumulated differential exceeded the production; however the potentially confusing part here is that the sleep in the iterate competes with the scheduling in the emitter. This becomes clearer of a relationship when the boundaries of isolation are crossed. |
| 360 | +The last value is never observed because the program ends before it would be. If the program did not terminate then another value would be observed. |
355 | 361 |
|
356 | 362 | Observations can be used across boundaries of concurrency. This is where the iteration is done on a different isolation than the mutations. The types however are accessed always in the isolation that the creation of the Observations closure is executed. This means that if the `Observations` instance is created on the main actor then the subsequent calls to the closure will be done on the main actor.
|
357 | 363 |
|
|
0 commit comments