# \#cancellation

**URL:** https://forums.swift.org/tag/cancellation/585.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [\`sending\` cancellation handler in \`withTaskCancellationHandler\`](https://forums.swift.org/t/sending-cancellation-handler-in-withtaskcancellationhandler/87222)

<div class="topic-metadata">

**Author:** [@soumyamahunt](https://forums.swift.org/u/soumyamahunt)\
**Replies:** 6\
**Last updated:** [June 10, 2026, 8:34am UTC](https://forums.swift.org/t/sending-cancellation-handler-in-withtaskcancellationhandler/87222 "2026-06-10T08:34:42Z")

</div>

In my use case I need to handle cancellation with withTaskCancellationHandler that mutates a non-Sendable actor isolated value. The current API accepts the actor isolation input but only accepts Sendable cancellation han…

---

## [Should Swift warn about ineffective cancellation checks inside unstructured tasks?](https://forums.swift.org/t/should-swift-warn-about-ineffective-cancellation-checks-inside-unstructured-tasks/85245)

<div class="topic-metadata">

**Author:** [@PacePaf](https://forums.swift.org/u/PacePaf)\
**Replies:** 11\
**Last updated:** [March 11, 2026, 1:33pm UTC](https://forums.swift.org/t/should-swift-warn-about-ineffective-cancellation-checks-inside-unstructured-tasks/85245 "2026-03-11T13:33:29Z")

</div>

These checks can look valid while actually providing a false sense of cancellation safety: Task { try Task.checkCancellation() // never throws here guard !Task.isCancelled else { return } // never returns here } A…

---

## [How expensive is a task cancellation check?](https://forums.swift.org/t/how-expensive-is-a-task-cancellation-check/84992)

<div class="topic-metadata">

**Author:** [@ole](https://forums.swift.org/u/ole)\
**Replies:** 2\
**Last updated:** [February 25, 2026, 7:26pm UTC](https://forums.swift.org/t/how-expensive-is-a-task-cancellation-check/84992 "2026-02-25T19:26:13Z")

</div>

I'm trying to build an intuition for how expensive a single task cancellation check is. My ultimate goal is to get (or write myself) some guidance on how often a computation-intensive function should perform manual cance…

---

## [Automatically Cancelling Continuations](https://forums.swift.org/t/automatically-cancelling-continuations/72960)

<div class="topic-metadata">

**Author:** [@nikolai.ruhe](https://forums.swift.org/u/nikolai.ruhe)\
**Replies:** 12\
**Last updated:** [December 12, 2024, 5:52am UTC](https://forums.swift.org/t/automatically-cancelling-continuations/72960 "2024-12-12T05:52:44Z")

</div>

When writing async code I often need to combine CheckedContinuation APIs with task cancellation. Here's a motivating example for a network fetch de-duplication service: func fetch(from url: URL) async throws -\> Data { …

---

## [Considerations when adapting completion-block async code to Swift concurrency via \`withTaskCancellationHandler\` & \`withCheckedContinuation\`](https://forums.swift.org/t/considerations-when-adapting-completion-block-async-code-to-swift-concurrency-via-withtaskcancellationhandler-withcheckedcontinuation/68892)

<div class="topic-metadata">

**Author:** [@jamieQ](https://forums.swift.org/u/jamieQ)\
**Replies:** 2\
**Last updated:** [December 8, 2023, 6:46pm UTC](https://forums.swift.org/t/considerations-when-adapting-completion-block-async-code-to-swift-concurrency-via-withtaskcancellationhandler-withcheckedcontinuation/68892 "2023-12-08T18:46:40Z")

</div>

i was recently thinking about some code that adapts a completion-block-based API to Swift concurrency with support for cancelation of the async work. i found things a bit more complex at times than i initially expected, …

---

## [Task Scheduling and Cancellation](https://forums.swift.org/t/task-scheduling-and-cancellation/61246)

<div class="topic-metadata">

**Author:** [@StarLard](https://forums.swift.org/u/StarLard)\
**Replies:** 3\
**Last updated:** [November 7, 2022, 7:47pm UTC](https://forums.swift.org/t/task-scheduling-and-cancellation/61246 "2022-11-07T19:47:52Z")

</div>

The Structured Concurrency proposal outlines that Tasks go through the following lifecycle: suspended -\> running -\> completed, where it may go through any number of alternating states between running and suspended at sus…

---

## [Flaky effect cancellation test](https://forums.swift.org/t/flaky-effect-cancellation-test/60492)

<div class="topic-metadata">

**Author:** [@dominik.mayer](https://forums.swift.org/u/dominik.mayer)\
**Replies:** 2\
**Last updated:** [September 25, 2022, 1:11pm UTC](https://forums.swift.org/t/flaky-effect-cancellation-test/60492 "2022-09-25T13:11:53Z")

</div>

Hi, I'm trying to test cancelling an effect that loads media and sends updates back to the store. Simplified it looks like this: case .binding(\\.mediaLoader.$results): let results = state.mediaLoader.results st…

---

## [Creating child task after a task has been cancelled](https://forums.swift.org/t/creating-child-task-after-a-task-has-been-cancelled/52757)

<div class="topic-metadata">

**Author:** [@tourultimate](https://forums.swift.org/u/tourultimate)\
**Replies:** 4\
**Last updated:** [October 13, 2021, 2:24am UTC](https://forums.swift.org/t/creating-child-task-after-a-task-has-been-cancelled/52757 "2021-10-13T02:24:13Z")

</div>

What is the expected behavior here: func testChildTaskCancellation() async throws { let t = Task { await Task.yield() XCTAssertTrue(Task.isCancelled) let child = Task { …

---

## [Task Cancellation Bug?](https://forums.swift.org/t/task-cancellation-bug/52740)

<div class="topic-metadata">

**Author:** [@tourultimate](https://forums.swift.org/u/tourultimate)\
**Replies:** 5\
**Last updated:** [October 13, 2021, 1:15am UTC](https://forums.swift.org/t/task-cancellation-bug/52740 "2021-10-13T01:15:44Z")

</div>

Checking the isCancelled property on a Task doesn't seem to be reporting the correct value. This test fails 100/100 times: func testCancelBug() async { let t = Task { await Task.yield() …
