Skip to content

Commit f507095

Browse files
authored
[Observation]Add a few clarifications and refinements to address the last bits of feedback for the review thread (#2874)
1 parent e12580d commit f507095

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

proposals/0475-observed.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Task.detached {
173173
}
174174
```
175175

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
177177
be achieved without needing an extra buffer since the suspension of each side of
178178
the iteration are continuations resuming all together upon the accessor's
179179
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
257257
terminate with that given failure. Subsequent calls then to `next` on those
258258
iterators will return `nil` - indicating that the iteration is complete.
259259

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+
260266
## Behavioral Notes
261267

262268
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
351357
3 3
352358
```
353359

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.
355361

356362
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.
357363

0 commit comments

Comments
 (0)