# \#unstructured-task

**URL:** https://forums.swift.org/tag/unstructured-task/707.md

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

---

## [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…

---

## [For-await during cancelling a Task](https://forums.swift.org/t/for-await-during-cancelling-a-task/76627)

<div class="topic-metadata">

**Author:** [@safarafa](https://forums.swift.org/u/safarafa)\
**Replies:** 4\
**Last updated:** [December 14, 2024, 6:25pm UTC](https://forums.swift.org/t/for-await-during-cancelling-a-task/76627 "2024-12-14T18:25:07Z")

</div>

I've noticed, that when a Task is cancelled while the work is suspended (on some for-await), awaiting is "interrupted" and work is continued, event if the stream is constantly sending values (not in a example for simpli…

---

## [Can I create a Task but manually start it later in Swift Concurrency?](https://forums.swift.org/t/can-i-create-a-task-but-manually-start-it-later-in-swift-concurrency/72643)

<div class="topic-metadata">

**Author:** [@HoustonDuane](https://forums.swift.org/u/HoustonDuane)\
**Replies:** 4\
**Last updated:** [June 24, 2024, 2:31am UTC](https://forums.swift.org/t/can-i-create-a-task-but-manually-start-it-later-in-swift-concurrency/72643 "2024-06-24T02:31:42Z")

</div>

Hi all, I'm reading that when I create a Task, it is automatically started. What if I want to defer it until needed? Prior to Swift Concurrency, my project was using PromiseKit to do such a thing. A Promise\<T\> stores a …

---

## [Calling async code with task cancellation triggered by SwiftNIO channel](https://forums.swift.org/t/calling-async-code-with-task-cancellation-triggered-by-swiftnio-channel/70971)

<div class="topic-metadata">

**Author:** [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Replies:** 2\
**Last updated:** [April 8, 2024, 4:33pm UTC](https://forums.swift.org/t/calling-async-code-with-task-cancellation-triggered-by-swiftnio-channel/70971 "2024-04-08T16:33:11Z")

</div>

i have some code that is relying on unstructured tasks to send the right task cancellation signals into some async-colored code. try await stream.frames.executeThenClose { ( inbound:NIOAsyncChannelInboundStr…

---

## [Swift Concurrency: Keeping Completed Tasks as Cache Objects?](https://forums.swift.org/t/swift-concurrency-keeping-completed-tasks-as-cache-objects/70796)

<div class="topic-metadata">

**Author:** [@bdkjones](https://forums.swift.org/u/bdkjones)\
**Replies:** 11\
**Last updated:** [March 20, 2024, 3:45pm UTC](https://forums.swift.org/t/swift-concurrency-keeping-completed-tasks-as-cache-objects/70796 "2024-03-20T15:45:11Z")

</div>

Setup: Suppose I have a bunch of unstructured Task objects that each take a while to generate a CGImage from a remote file. I add these Task objects to a iVar on an Actor so that any new requests for the same image that …

---

## [Bad pointer dereference in stateless task](https://forums.swift.org/t/bad-pointer-dereference-in-stateless-task/68244)

<div class="topic-metadata">

**Author:** [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Replies:** 1\
**Last updated:** [November 3, 2023, 11:47pm UTC](https://forums.swift.org/t/bad-pointer-dereference-in-stateless-task/68244 "2023-11-03T23:47:49Z")

</div>

Here's my entire code: Task { try! await Task.sleep(nanoseconds: 1\_000\_000) print("Hello") } Guess what it outputs? (Hint: it's not "Hello") That's right, it segfaults! Segmentation fault (core dumped) 💣 Program…

---

## [Passing values to an Task/Actor in serial manner](https://forums.swift.org/t/passing-values-to-an-task-actor-in-serial-manner/64706)

<div class="topic-metadata">

**Author:** [@MuniekMg](https://forums.swift.org/u/MuniekMg)\
**Replies:** 22\
**Last updated:** [May 2, 2023, 1:20pm UTC](https://forums.swift.org/t/passing-values-to-an-task-actor-in-serial-manner/64706 "2023-05-02T13:20:01Z")

</div>

Hi, I have a really simple code, which send some values from synchronous func to async func. Values received in async func are not in order. func sendValues() { for i in 0..\<1000 { Task { …

---

## [EXC\_BAD\_ACCESS when using \`Task.detached\` on a class](https://forums.swift.org/t/exc-bad-access-when-using-task-detached-on-a-class/62944)

<div class="topic-metadata">

**Author:** [@grzegorzkrukowski](https://forums.swift.org/u/grzegorzkrukowski)\
**Replies:** 3\
**Last updated:** [February 5, 2023, 8:37am UTC](https://forums.swift.org/t/exc-bad-access-when-using-task-detached-on-a-class/62944 "2023-02-05T08:37:01Z")

</div>

I'm having hard time understanding where multiple crashes are coming from this simple code. typealias RepositoryData = Set\<RepositoryItem\> //RepositoryItem is a Sendable, struct final class Repository { private var da…

---

## [Understanding why an async function that returns almost immediately puts system in a bad state in Swift](https://forums.swift.org/t/understanding-why-an-async-function-that-returns-almost-immediately-puts-system-in-a-bad-state-in-swift/60133)

<div class="topic-metadata">

**Author:** [@cantor](https://forums.swift.org/u/cantor)\
**Replies:** 10\
**Last updated:** [September 6, 2022, 8:38pm UTC](https://forums.swift.org/t/understanding-why-an-async-function-that-returns-almost-immediately-puts-system-in-a-bad-state-in-swift/60133 "2022-09-06T20:38:28Z")

</div>

I do state management locally in my class using a enum. If a particular async work is not done then I kick it off in a Task and then await that task's result. Once the async function completes, it caches the values and u…

---

## [The hardest part to understand the new Structured concurrency system is](https://forums.swift.org/t/the-hardest-part-to-understand-the-new-structured-concurrency-system-is/58493)

<div class="topic-metadata">

**Author:** [@AlexSedykh](https://forums.swift.org/u/AlexSedykh)\
**Replies:** 1\
**Last updated:** [August 25, 2022, 2:25am UTC](https://forums.swift.org/t/the-hardest-part-to-understand-the-new-structured-concurrency-system-is/58493 "2022-08-25T02:25:42Z")

</div>

Unstructured Tasks within Actors If called from the context of an existing task: if executed within the scope of a specific actor function: inherit the actor's execution context and run the task on its executor, rat…

---

## [TSAN for detecting data race](https://forums.swift.org/t/tsan-for-detecting-data-race/58666)

<div class="topic-metadata">

**Author:** [@somu](https://forums.swift.org/u/somu)\
**Replies:** 5\
**Last updated:** [July 5, 2022, 5:28am UTC](https://forums.swift.org/t/tsan-for-detecting-data-race/58666 "2022-07-05T05:28:14Z")

</div>

Hi, Please let me know if TSAN is off topic, apologies. Is TSAN (thread sanitiser on Xcode) the right way to detect data races? If I uncomment the print statements, the data races are detected. However If leave th…
