تخطَّ إلى المحتوى

Fire And Forget Task (ARCH9021)

هذا المحتوى غير متوفر بلغتك بعد.

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.

func refresh() {
Task { try await repository.sync() }
}
func refresh() async throws {
try await repository.sync()
}
// or keep the handle: refreshTask = Task { ... } and cancel it in deinit

Make the caller async, or keep the Task handle so it can be awaited or cancelled.