Cancelling tasks (swift concurrency Task)
Asked on 2025-07-16
1 search
In Swift concurrency, tasks are the fundamental unit of concurrent execution. They represent independent concurrent execution contexts and are lightweight, allowing you to create many of them. You can wait for a task to complete to get its result, or you can cancel it if its work becomes unnecessary. This makes tasks particularly useful for handling operations like HTTP requests, where you might need to cancel a task if the request is no longer needed.
For more detailed information on Swift concurrency, you can refer to the session Embracing Swift concurrency, which covers the introduction of concurrency, concurrent functions, and more. Additionally, the session A Swift Tour: Explore Swift’s features and design provides an overview of concurrency in Swift, including task management and cancellation.

A Swift Tour: Explore Swift’s features and design
Learn the essential features and design philosophy of the Swift programming language. We’ll explore how to model data, handle errors, use protocols, write concurrent code, and more while building up a Swift package that has a library, an HTTP server, and a command line client. Whether you’re just beginning your Swift journey or have been with us from the start, this talk will help you get the most out of the language.

Embracing Swift concurrency
Join us to learn the core Swift concurrency concepts. Concurrency helps you improve app responsiveness and performance, and Swift is designed to make asynchronous and concurrent code easier to write correctly. We’ll cover the steps you need to take an app through from single-threaded to concurrent. We’ll also help you determine how and when to make the best use of Swift concurrency features – whether it’s making your code more asynchronous, moving it to the background, or sharing data across concurrent tasks.

What’s new in Xcode
Discover the latest productivity and performance advancements in Xcode 26. Learn how to leverage large language models in your development workflow. Explore editing and debugging enhancements, improved performance and testing tools, and Swift Build - the open-source build system engine used by Xcode.