---
title: cancel()
framework: swift
role: symbol
role_heading: Instance Method
path: swift/unsafecurrenttask/cancel()
---

# cancel()

Cancel the current task.

## Declaration

```swift
func cancel()
```

## Discussion

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. note: withTaskCancellationShield(operation:) note: Task/hasActiveTaskCancellationShield
