<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UnsafeCurrentTask/cancel()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sct6cancelyyF"
  },
  "title" : "cancel()"
}
-->

# cancel()

Cancel the current task.

```
func cancel()
```

## Discussion

The task will be immediately cancelled and cancellation will propagate towards any child tasks it has.

### Interaction with Task Cancellation Shields

Note that cancellation may not be observed if a task is currently executing with an
active task cancellation shield. Refer to cancellation shield documentation for detailed semantics.

> SeeAlso: ``withTaskCancellationShield(operation:)-(()->Value)``

> SeeAlso: ``doc://com.apple.Swift/documentation/Swift/Task/hasActiveCancellationShield``

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)