Index of every page on this site: llms.txt
All skills
demianturner avatar

/m23-avoid-task-detached

@3031b90
Run it yourself

Refactor Task.detached used for CPU work in Swift 6.2+ TCA effects. Use when preserving effect cancellation and actor isolation matters; do not apply to intentionally independent tasks.

Use this Skill: https://skilld.dev/gh/demianturner/swift-skills/m23-avoid-task-detached

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈53 tokens for metadata: the name and description. ≈499 when used: this file.

Description uses 2.6% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈211 characters, or 2.6%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Avoid unnecessary Task.detached in TCA effects

When a reducer launches Task.detached merely to move expensive work off the main actor, move that work into an async dependency operation and await it from the .run effect. For CPU-intensive synchronous work, an explicitly @concurrent async function can run the processing outside the caller's actor isolation in Swift 6.2+.

Before changing code, check why the detached task exists, who owns its lifetime, and how the effect is cancelled. A genuinely independent task may need a separate lifetime; this skill does not require removing it.

Preserve execution and cancellation

  • Keep the reducer responsible for starting the effect and receiving the result as an action. Put processing behind a dependency so it remains replaceable in tests.
  • Use @concurrent when CPU work must leave the caller's actor. Do not add it to async operations that already suspend efficiently, such as URLSession requests.
  • Pass values across isolation boundaries in a way Swift's sendability rules permit. Keep main-actor state out of the processing function.
  • Preserve effect cancellation and any existing request identity or stale-result checks. CPU loops may need cooperative cancellation checks; awaiting a function does not interrupt synchronous work automatically.
  • Use an actor when processing must protect shared mutable state. Actor isolation alone does not guarantee execution on a particular thread.

@concurrent selects concurrent execution outside actor isolation; it does not reserve a background thread. If the operation performs substantial blocking I/O, assess an appropriate I/O strategy separately instead of assuming @concurrent solves thread occupancy.

Check the affected effect's success, failure, and cancellation behavior, and confirm expensive processing no longer runs on the main actor. When compiler or language settings differ from Swift 6.2, verify the supported isolation spelling before applying this pattern.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts1mo2 checks · Risk LOW
  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

Signed by skilld at 3031b90. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated last month
metadata
{
  "short-description": "Replace detached work in TCA effects"
}

README badge

README badge for demianturner/swift-skills/m23-avoid-task-detached