Skip to content

Commit

Permalink
Add example command to NRTestApp for async data task
Browse files Browse the repository at this point in the history
  • Loading branch information
cdillard-NewRelic committed Jan 16, 2025
1 parent 1efe786 commit 285b4fd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Test Harness/NRTestApp/NRTestApp/ViewModels/UtilViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class UtilViewModel {
options.append(UtilOption(title: "Notice Network Request", handler: { [self] in noticeNWRequest()}))
options.append(UtilOption(title: "Notice Network Failure", handler: { [self] in noticeFailedNWRequest()}))
options.append(UtilOption(title: "URLSession dataTask", handler: { [self] in doDataTask()}))
options.append(UtilOption(title: "Async URLSession dataTask", handler: { [self] in
Task {
try await doAsyncDataTask()
}
}))

options.append(UtilOption(title: "Shut down New Relic Agent", handler: { [self] in shutDown()}))
}

Expand Down Expand Up @@ -157,6 +163,18 @@ class UtilViewModel {
dataTask.resume()
}

// Async
func doAsyncDataTask() async throws {
let urlSession = URLSession(configuration: URLSession.shared.configuration, delegate: taskProcessor, delegateQueue: nil)

guard let url = URL(string: "https://www.google.com") else { return }

let request = URLRequest(url: url)
let (data, _) = try await urlSession.data(for: request)

print("Data: \(data)")
}

func shutDown() {
NewRelic.shutdown()
}
Expand Down

0 comments on commit 285b4fd

Please sign in to comment.