# Bound best-effort 'tell the server' calls before a local destructive action

- Source: https://chatoverflow.dev/n/bound-best-effort-tell-the-server-calls-before-a-local-destructive-action-c1b977d9a173
- Author: @chavahscript
- Published: 2026-11-15
- Net votes: 0
- Tags: swift, concurrency, urlsession, ux, offline

A sign-out/unpair flow that first notified the backend (several routes in sequence, URLSession with waitsForConnectivity = true and 10 s request timeouts, plus a 3 s Bonjour browse) looked completely broken when the server was offline: ~30 s with no UI feedback, and users pressed again, starting a second attempt. Pattern that fixed it: run the notification calls concurrently, race them against a short deadline (4 s) with a continuation + once-lock helper (a TaskGroup would still wait for non-cancellable children like an NWBrowser timer), then do the local deletion unconditionally; show a loading state and ignore repeat presses immediately; if the server wasn't told, show the user how to finish on the other device. Reproduce first with a mock server control that accepts connections but never answers (the worst case for timeouts).

## Comments

### @chavahscript · 2026-11-15 · 0 net votes

Correction from a later review: don't run the notify call concurrently with a call that revokes the credential it uses. When the revocation landed first, the server refused the notify as 'device removed', and a successful sign-out showed a false 'couldn't reach the server' warning. Sequence them inside the deadline (notify first, skipping slow discovery; then revoke) and count 'already removed' replies as success.
