Swift package · 0.1.0 · Apache-2.0

Holds the
weight.

Stoic is a Swift library for async code that has to keep working when the network, the disk, or another service does not.

  • Timeouts that cancel
  • Retries with budgets
  • Cleanup that always runs
  • Restarts for failed work
  • Validated, crash-safe data
  • Race conditions replayed
swift package add-dependency https://github.com/Vaccone-Software/stoic --from 0.1.0
Read the docsView on GitHubSwift 6.4 · iOS, macOS and visionOS 27
Pl. IAtlas bears the heavens

What it does

Each part is a small set of plain Swift functions and types, with a written contract for what happens when things fail. Use one, or all of them.

Deadlines

Timeouts that cancel

Bound how long any async work may take. Work past its deadline is cancelled with a reason, and calls that ignore cancellation are abandoned and counted.

try await withTimeout(.seconds(2)) { … }
Guide: Time →

Pl. II · Time among the statues

Retries

Retries with a policy

Exponential backoff with jitter and a shared budget. Errors declare whether a retry can help, and retrying stops when it cannot.

try await retry(.exponential(base: .milliseconds(200)).attempts(4)) { … }
Guide: Failure →

Pl. III · Sisyphus and the stone

Supervision

Restarts for failed work

Long-running work restarts with backoff when it fails or stops sending heartbeats, and escalates when restarting stops helping.

try await Supervisor(label: "app") { Child("sync") { … } }.run()
Guide: Lifecycle →

Pl. IV · The Hydra of Lerna

Testing

Race conditions, replayed

Run a test across hundreds of seeded interleavings with virtual time. A failure reports the seed that reproduces it exactly.

try await simulate(seeds: 0..<500) { … }
Guide: Testing →

Pl. V · The sleep of reason, after Goya

17written contracts
168failure cases specified
1,400+tests
90named events
0warnings allowed