NNovaNetworkClientSwift networkingGitHub ↗

Intermediate · 14 min

Load a bounded batch

Fetch an ordered collection without unbounded fan-out.

You’ll buildAn ordered batch with an explicit concurrency ceiling and decoded values.
1
Step 1

Create ordered requests

Input position becomes output position even when responses complete out of order.

Loadaboundedbatch.swift
let requests = (1...12).map { id in
    APIRequest(
        method: .get,
        url: URL(string: "https://jsonplaceholder.typicode.com/todos/\(id)")!
    )
}
2
Step 2

Bound concurrency

The client starts at most four child requests at once.

Loadaboundedbatch.swift
let payloads = try await client.loadBatch(
    requests: requests,
    authScope: "public",
    batchOptions: .init(maxConcurrentRequests: 4)
)
3
Step 3

Decode in order

The resulting payload array preserves request order.

Loadaboundedbatch.swift
let decoder = JSONDecoder()
let todos = try payloads.map {
    try decoder.decode(Todo.self, from: $0)
}
✓

Tutorial complete

An ordered batch with an explicit concurrency ceiling and decoded values.