How come I can do something like in fetchNoError()
, but not fetchError()
? It seems pretty dubious to enforce having to mutate actor stored properties only within the actual actor context. As in fetch()
, we're accessing it through self, so I imagine that any safety that is bestowed by the actor should be able to be bestowed via access through the actor itself, i.e., it's not like I'm capturing the stored property and mutating it independently of self
.
Can someone lend some clarity on why it is done this way?
actor IGMConfigFetchManager: IGMConfigFetchManaging {
private var outstandingRequests: OutstandingRequests
init() {
self.outstandingRequests = .init()
}
func fetchError() async {
await Global.doStuff(onCompletion: { [weak self] in
self?.outstandingRequests.closeOut() // mutating (error in Swift 6)
})
}
func fetchNoError() {
await Global.doStuff(onCompletion: { [weak self] in
self?.closeOut() // no error
})
}
func closeOut() {
self.outstandingRequests.closeOut()
}
}