You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It also allows actor functions to be extracted into global or local functions, so code can be refactored without breaking actor isolation. Due to `isolated` parameters, the `self` parameter of an actor function is actually not that special: it merely defaults to `isolated` because of the context in which it is declared. For example, type of `BankAccount.deposit(amount:)`, defined above, is a curried function that involves an isolated `self`:
212
212
@@ -612,6 +612,35 @@ By default, the mutable instance stored properties (declared with `var`) of an a
612
612
613
613
> **Rationale**: `nonisolated(unsafe)` allows specific stored instance properties to opt out of actor isolation checking, allowing careful developers to implement their own synchronization mechanisms.
614
614
615
+
It is legal, albeit uncommon, to declare an actor instance method as `nonisolated`_and_ have it accept a different `isolated` actor parameter. Since nonisolated can be understood as removing the implicit `isolated self`, the addition of an `isolated` parameter still properly respects the requirement that there be only a single actor with which a function is isolated.
greeter.take(creditCard) // error: nonisolated Worker function cannot refer to isoalted state 'creditCard', function is actor-isolated to 'greeter: isolated Greeter'
631
+
}
632
+
}
633
+
```
634
+
635
+
Exhibits the following semantics:
636
+
637
+
- this function is isolated with the `Greeter` actor, and *not* the `Worker` (!),
638
+
- as such, it can synchronously invoke the `greeter.greet` function.
639
+
- it cannot refer to isolated state of the Worker,
640
+
- it will execute on the `Greeter` actor.
641
+
642
+
In practice this means that this function can only be invoked by a greeter which passes `self` as an isolated parameter to the hello function of the worker it is about to greet. The `hello` function can refer to the actors private, non isolated state, such as a constant (or other `nonisolated` variables).
643
+
615
644
### Actor isolation checking
616
645
617
646
Any given declaration in a program is either isolated to a specific actor or is non-isolated.
0 commit comments