How to "fire and forget" work on an actor?

My first instinct was to do this:

actor FooActor {
    var x = 0

    nonisolated func incrementEventually() {
        Task { [isolated self] in
            self.x += 1
        }
    }
}

But apparently [isolated self] isn't a valid capture.

I don't have a pressing need for this, I was just exploring this as one option for a potential problem, so this is more out of curiosity than anything else.

2 Likes

There was a pitch to enable things like [isolated self], but it hasn't seen any progress in the last few months. I believe that for now, you'd need to pull self.x += 1 out into a separate isolated function.

Task {
  await self.incrementX() 
}
5 Likes

I think you'd need to explicitly await here: await self.incrementX(), right?

1 Like

Oh, yep. Sorry, forums are not a compiler! :slight_smile: I'll edit it to avoid confusion later.

1 Like