Fire And Forget Task (ARCH9021)
Esta página aún no está disponible en tu idioma.
Key swift.async.fire-and-forget-task · Severity warning · Category async
Flags Task { } / Task.detached { } whose handle is discarded. A Task { @MainActor in ... } hop is excepted: the work IS the hop and there is nothing to cancel.
Incorrect
Section titled “Incorrect”func refresh() { Task { try await repository.sync() }}Correct
Section titled “Correct”func refresh() async throws { try await repository.sync()}// or keep the handle: refreshTask = Task { ... } and cancel it in deinitMake the caller async, or keep the Task handle so it can be awaited or cancelled.