actor Counter {
private static let data = ["A", "B", "C"]
private var cursor = 0
private let queue = SerialQueueThrowing()
private func orderedUpdate() async {
cursor += 1
await Task.yield()
debugPrint(Self.data[cursor % Self.data.count])
}
func update() async throws {
try await queue.enqueue {
await self.orderedUpdate()
}
}
}
I think making
orderedUpdate()privatein your final example would be the most realistic usage: