diff --git a/Examples/BrandGame/BrandGame/View/Menu/StressTests/Network/NetworkRequest.swift b/Examples/BrandGame/BrandGame/View/Menu/StressTests/Network/NetworkRequest.swift index f65fa71c..7c6d4ed7 100644 --- a/Examples/BrandGame/BrandGame/View/Menu/StressTests/Network/NetworkRequest.swift +++ b/Examples/BrandGame/BrandGame/View/Menu/StressTests/Network/NetworkRequest.swift @@ -52,6 +52,27 @@ extension NetworkStressTest { task.resume() } + + func execute() async -> (NetworkResponse?) { + let before = Date() + do { + let response = try await URLSession.shared.data(for: .init(url: url)) + let after = Date() + guard let httpResponse = response.1 as? HTTPURLResponse else { + return nil + } + + return NetworkResponse( + id: idx, + requestURL: url, + response: httpResponse, + rtt: after.timeIntervalSince(before) + ) + } catch let exception { + print(exception.localizedDescription) + return nil + } + } } struct NetworkResponse: Sendable, Identifiable { diff --git a/Examples/BrandGame/BrandGame/View/Menu/StressTests/Network/NetworkStressTest.swift b/Examples/BrandGame/BrandGame/View/Menu/StressTests/Network/NetworkStressTest.swift index 803b2126..abceee55 100644 --- a/Examples/BrandGame/BrandGame/View/Menu/StressTests/Network/NetworkStressTest.swift +++ b/Examples/BrandGame/BrandGame/View/Menu/StressTests/Network/NetworkStressTest.swift @@ -14,15 +14,21 @@ struct NetworkStressTest: View { ] - @State var inputURL: String = NetworkStressTest.quickURLs.first! - @State var inputCount: UInt = 20 - @State var didSubmit: Bool = false + @State private var inputURL: String = NetworkStressTest.quickURLs.first! + @State private var inputCount: UInt = 20 + @State private var didSubmit: Bool = false + @State private var useNewConcurrency: Bool = false - @State var responses: [NetworkResponse] = [] + @State private var responses: [NetworkResponse] = [] var body: some View { VStack { Form { + Section("Configuration") { + Toggle(isOn: $useNewConcurrency) { + Text("Use async/await?") + } + } List { Section("Quick URLs") { ForEach(NetworkStressTest.quickURLs, id: \.self) { item in @@ -85,28 +91,47 @@ struct NetworkStressTest: View { } responses = [] - let group = DispatchGroup() - - for index in 0.. Void) { + let group = DispatchGroup() + + for index in 0..