Open mman opened 1 month ago
For anybody reaching this bug. For the moment the proper solution under Linux seems to be:
actor X {
let queue = DispatchQueue(label: "queue")
private let executor: DispatchQueueExecutor
final class DispatchQueueExecutor: SerialExecutor {
private let queue: DispatchQueue
init(queue: DispatchQueue) {
self.queue = queue
}
func enqueue(_ job: UnownedJob) {
self.queue.async {
job.runSynchronously(on: self.asUnownedSerialExecutor())
}
}
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
UnownedSerialExecutor(ordinary: self)
}
func checkIsolated() {
dispatchPrecondition(condition: .onQueue(self.queue))
}
}
nonisolated public var unownedExecutor: UnownedSerialExecutor {
executor.asUnownedSerialExecutor()
}
init() {
self.executor = DispatchQueueExecutor(queue: queue)
}
/// remaining logic
}
Probably another inconsistency, but the following code creating an
actor
backed by serialDispatchQueue
works on macOS and does not compile under Linux:Under Linux it produces the following error: