Instance MethodConcurrency


Indicates that the task should stop running.

  • Available when Success conforms to Sendable and Failure conforms to Error

  • iOS 13.0+
  • macOS 10.15+
  • tvOS 13.0+
  • watchOS 6.0+
func cancel()


Task cancellation is cooperative: a task that supports cancellation checks whether it has been canceled at various points during its work.

Calling this method on a task that doesn’t support cancellation has no effect. Likewise, if the task has already run past the last point where it would stop early, calling this method has no effect.

  • SeeAlso: Task.checkCancellation()