swift-concurrency

Design Swift async/await flows with TaskGroup, Actor isolation, and cancellation handling.

415|44|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/notque/vexjoy-agent --skill swift-concurrency-notque
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-concurrency
Source: https://github.com/notque/vexjoy-agent/tree/main/skills/engineering/swift-concurrency
Command: npx skills add https://github.com/notque/vexjoy-agent --skill swift-concurrency-notque

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Swift concurrency patterns are easy to get subtly wrong (data races, leaking tasks, blocking the main actor), leading to flaky bugs and compiler warnings that stall development.

Core Features & Use Cases

  • Structured concurrency guidance: Prefer async/await and TaskGroup over unstructured Task usage to get correct cancellation and error propagation in real workflows.
  • Actor isolation & main-thread confinement: Use Actors, @MainActor, and nonisolated to safely protect shared mutable state while keeping UI work responsive.
  • Sendable correctness & failure-mode prevention: Apply Sendable/@Sendable and common pitfall fixes (blocking, task leaking, actor reentrancy hazards) to keep Swift 6 strict checks green.

Quick Start

Apply the conventions from the attached references to your Swift async code and verify you use TaskGroup, actors for shared mutable state, and Sendable types where values cross concurrency boundaries.

Frequently Asked Questions about swift-concurrency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent data races and task leaks in Swift async code?

Apply structured concurrency patterns by preferring async/await and TaskGroup over unstructured Task usage to ensure correct cancellation and error propagation, while enforcing Actor isolation to safely protect shared mutable state across asynchronous boundaries.

What is the best way to handle shared mutable state in Swift concurrency?

The best way to handle shared mutable state in Swift concurrency is using Actors and @MainActor. Actors serialize access to their state, while @MainActor confines UI-related work to the main thread, keeping interfaces responsive without explicit locking mechanisms.

How do I use Sendable closures to pass data across concurrency boundaries in Swift?

Use Sendable and @Sendable to mark types and closures that cross concurrency boundaries as safe. This ensures value types are immutable or safely synchronized, satisfying Swift 6 strict concurrency checks and preventing data races during concurrent execution.

How do I manage cancellation across networking and streaming tasks in Swift?

Manage cancellation in Swift networking and streaming tasks by using structured concurrency patterns like TaskGroup. This ensures that when a parent task is cancelled, the cancellation automatically propagates to all child tasks, preventing orphaned network requests and resource leaks.

Does Swift structured concurrency work with AsyncSequence for streaming data?

Yes, Swift structured concurrency works seamlessly with AsyncSequence for streaming data. You can iterate over an AsyncSequence using async/await within a TaskGroup, ensuring proper cancellation propagation and structured error handling across your streaming workflows.

Why does my Swift actor reentrancy cause unexpected state mutations?

Swift actor reentrancy can cause unexpected state mutations when an actor method suspends and allows another interleaving task to execute. Prevent this hazard by minimizing suspension points within actor methods and validating state after awaiting external asynchronous calls.