Estou migrando para o Swift 6 e recebo um erro enquanto o Swift 5 compila.
O envio de 'newElement' corre o risco de causar disputas de dados
Por que isso acontece e como posso corrigir?
actor AsyncStack<Element> {
private var storage = [Element]()
private var awaiters = [CheckedContinuation<Element,Error>]()
/// Push a new element onto the stack
/// - Parameter newElement: The element to push
/// - Returns: Void
public func push(_ newElement: Element) async -> Void {
if !awaiters.isEmpty {
let awaiter = awaiters.removeFirst()
awaiter.resume(returning: newElement) // ERROR in this line
} else {
storage.insert(newElement, at: 0)
}
}
/// Pop the element at the top of the stack or wait until an element becomes available
/// - Returns: The popped element
public func popOrWait() async throws -> Element {
if let element = storage.popLast() {
return element
}
return try await withCheckedThrowingContinuation { continuation in
awaiters.append(continuation)
}
}
}