1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| extension XSPersonalViewController { private func testConcurrentRequests() { Task { let startTime = Date() await XSClient.shared.clearTokenExpiration() ASLog("Token expiration cleared for testing at \(startTime)") try await withThrowingTaskGroup(of: (Int, [String: Any], TimeInterval).self) { group in for i in 1...5 { group.addTask { let requestStart = Date() let result = try await XSHttpManager.postRequest( urlString: "/auth/user/getUserInfo", parameters: ["userName": "test\(i)@example.com"] ) let elapsed = Date().timeIntervalSince(requestStart) return (i, result, elapsed) } } try await Task.sleep(nanoseconds: 1_000_000_000) for i in 6...8 { group.addTask { let requestStart = Date() let result = try await XSHttpManager.postRequest( urlString: "/auth/user/getUserInfo", parameters: ["userName": "test\(i)@example.com"] ) let elapsed = Date().timeIntervalSince(requestStart) return (i, result, elapsed) } } for try await (index, result, elapsed) in group { ASLog("Request \(index) completed with result: \(result)") ASLog("Request \(index) took \(elapsed) seconds") } } let totalTime = Date().timeIntervalSince(startTime) ASLog("All requests completed in \(totalTime) seconds") } } }
|