NNovaNetworkClientSwift networkingGitHub ↗

Intermediate · 12 min

Share concurrent requests

See equivalent callers join one in-flight network operation.

You’ll buildTwo concurrent callers that resolve from one coalesced transport operation.
1
Step 1

Create one stable request

Coalescing begins with deterministic request identity.

Shareconcurrentrequests.swift
let request = APIRequest(
    method: .get,
    url: URL(string: "https://jsonplaceholder.typicode.com/todos/1")!
)
let authScope = "public"
2
Step 2

Start overlapping work

async let starts both calls before either result is awaited.

Shareconcurrentrequests.swift
async let first: Todo = client.load(
    request: request, authScope: authScope
)
async let second: Todo = client.load(
    request: request, authScope: authScope
)
3
Step 3

Await both callers

Both consumers receive their own typed value while the underlying task is shared.

Shareconcurrentrequests.swift
let (left, right) = try await (first, second)
print(left.id, right.id)
✓

Tutorial complete

Two concurrent callers that resolve from one coalesced transport operation.