Actor isolation
SwiftSonicClient is a Swift actor. Every API call is async and runs serialized on the actor — no shared mutable state escapes, no manual locking required.
What this means in practice
Section titled “What this means in practice”- A single
SwiftSonicClientinstance is safe to share across tasks, view models, or background workers. - Concurrent calls into the client are serialized in actor-mailbox order. The HTTP work itself runs on
URLSessionin parallel; the bookkeeping (config access, token derivation, observers) is what’s serialized.
You probably do not need multiple clients
Section titled “You probably do not need multiple clients”A common reflex is to spin up one client per task to “avoid contention”. Don’t. The actor handles contention. Multiple clients sharing the same ServerConfiguration would just duplicate transport state.
Use one SwiftSonicClient per logical server connection.
Crossing isolation domains
Section titled “Crossing isolation domains”Because all the public types in SwiftSonic are Sendable, you can hand response models off to other actors, structured concurrency tasks, or MainActor view code without ceremony.
TODO: confirm that all response models in 0.6.x are marked
Sendable. Verify by spot-checkingSources/SwiftSonic/Models/.
Cancellation
Section titled “Cancellation”Standard structured concurrency cancellation applies. If the parent task is cancelled, in-flight requests are cancelled by URLSession and the call throws CancellationError.