I've got the following code in an actor:
public func save(volume: VolVolume, queue: MTLCommandQueue) async -> [SharedBlock] {
var blocks: [SharedBlock] = []
// XXX: does this break actor isolation?
await volume.saveStream({ status, block in
assert(status == VolVolumeStatus.OK)
blocks.append(self.store.insert(SharedBlock(volBlock: block)).1)
}, with: queue)
return blocks
}
saveStream
calls the passed function on a background thread multiple times. It looks like:
- (void) saveStream:(void(^)(VolVolumeStatus, VolBlock)) stream
withQueue:(id<MTLCommandQueue>)queue
completion:(void(^)())completion
I would think this breaks actor isolation because the callback is mutating self.store
without being inside an async function. Is that right?
I suppose I could rewrite saveStream
in Swift so that the callback passed to it is async. Is there an easier way?
thanks!