- Home
- Skills
- Rshankras
- Claude Code Apple Skills
- Concurrency Patterns
concurrency-patterns_skill
- Swift
56
GitHub Stars
6
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill rshankras/claude-code-apple-skills --skill concurrency-patterns- actors-and-isolation.md9.0 KB
- continuations-bridging.md10.1 KB
- migration-guide.md7.6 KB
- SKILL.md4.9 KB
- structured-concurrency.md10.6 KB
- swift62-concurrency.md7.4 KB
Overview
This skill provides practical Swift concurrency patterns focused on Swift 6.2 approachable concurrency, structured concurrency, actors, continuations, and migration strategies. It helps you review or build async code, fix data races and actor isolation errors, and migrate code to Swift 6 strict concurrency with minimal disruption.
How this skill works
I inspect compiler errors, runtime data races, and code structure to identify the right concurrency construct: async/await, TaskGroup, actors, continuations, or Swift 6.2 features like @concurrent and isolated conformances. I apply a decision tree to match the problem to patterns and a checklist to verify thread safety, Sendable conformance, cancellation handling, and proper continuation usage.
When to use it
- You see data race errors, actor isolation compiler errors, or crashes tied to shared state.
- You are migrating code to Swift 6 strict concurrency or adopting Swift 6.2 features.
- You need to convert completion-handler or delegate APIs to async/await safely.
- You want to run work in parallel with structured concurrency (async let, TaskGroup).
- You need to protect mutable shared state using actors or @MainActor for UI updates.
Best practices
- Keep UI work on @MainActor and avoid blocking calls there; use await for long operations.
- Protect shared mutable state with actors rather than locks or global queues.
- Prefer structured concurrency (async let, withTaskGroup) over unstructured Task {} for lifetime control.
- Ensure Sendable conformance for types crossing isolation boundaries and check for inadvertent captures.
- Handle Task cancellation explicitly using Task.isCancelled or Task.checkCancellation().
- Use withCheckedContinuation and AsyncStream carefully: call continuations exactly once and clean up delegate bridges.
Example use cases
- Migrate a view model to Swift 6 by marking UI state @MainActor and adjusting isolated conformances.
- Fix intermittent crashes by converting a shared mutable cache to an actor and auditing Sendable types.
- Parallelize multiple network requests using async let or withTaskGroup and aggregate results safely.
- Bridge a legacy delegate-based API to async/await using withCheckedContinuation or AsyncStream.
- Adopt Swift 6.2 @concurrent for explicit background work and apply isolated conformances to @MainActor types.
FAQ
@MainActor is for UI-bound state and coordination on the main thread; use a plain actor for background shared mutable state that doesn’t require main-thread execution.
When should I prefer async let vs withTaskGroup?
Use async let for a fixed small number of parallel operations. Use withTaskGroup when the number of tasks is dynamic or you need to add tasks progressively and collect results.