Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
MyActor Phase#1
actor class MyActor {
let immutable: String = "42"
var mutableArray: [String] = []
func synchronousFunction() {
mutableArray += ["syncFunction called"]
extension MyActor {
func asyncFunction(other: MyActor) async {
// allowed: an actor can access its internal state, even in an extension
self.mutableArray += ["asyncFunction called"]
// allowed: immutable memory can be accessed from outside the actor
// error: an actor cannot access another's mutable state
otherActor.mutableArray += ["not allowed"]
// error: either reading or writing
// allowed: async functions can call async functions on other actors
await other.asyncFunction(otherActor: self)
// error: only asynchronous functions can be called from outside the actor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment