Contents

isCancelled

A Boolean value that indicates whether the task should stop executing.

Declaration

var isCancelled: Bool { get }

Discussion

After the value of this property becomes true, it remains true indefinitely. There is no way to uncancel a task.

This property returns the actual cancellation state of the task, regardless of whether a cancellation shield is active. Use Task/isCancelled (the static property) if you need cancellation checking that respects active shields.

Instance property isCancelled ignores Task Cancellation Shields

The instance property task.isCancelled is not contextual and therefore does not respect cancellation shields. If a task was cancelled and is executing with an active cancellation shield, these properties will return the actual cancellation status of the specific task.

Prefer using Task.isCancelled (the static property) in most situations when checking the cancellation status from inside the task.

See Also

Canceling Tasks