File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Test Harness/NRTestApp/NRTestApp/ViewModels Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,12 @@ class UtilViewModel {
4343 options. append ( UtilOption ( title: " Notice Network Request " , handler: { [ self ] in noticeNWRequest ( ) } ) )
4444 options. append ( UtilOption ( title: " Notice Network Failure " , handler: { [ self ] in noticeFailedNWRequest ( ) } ) )
4545 options. append ( UtilOption ( title: " URLSession dataTask " , handler: { [ self ] in doDataTask ( ) } ) )
46+ options. append ( UtilOption ( title: " Async URLSession dataTask " , handler: { [ self ] in
47+ Task {
48+ try await doAsyncDataTask ( )
49+ }
50+ } ) )
51+
4652 options. append ( UtilOption ( title: " Shut down New Relic Agent " , handler: { [ self ] in shutDown ( ) } ) )
4753 }
4854
@@ -157,6 +163,18 @@ class UtilViewModel {
157163 dataTask. resume ( )
158164 }
159165
166+ // Async
167+ func doAsyncDataTask( ) async throws {
168+ let urlSession = URLSession ( configuration: URLSession . shared. configuration, delegate: taskProcessor, delegateQueue: nil )
169+
170+ guard let url = URL ( string: " https://www.google.com " ) else { return }
171+
172+ let request = URLRequest ( url: url)
173+ let ( data, _) = try await urlSession. data ( for: request)
174+
175+ print ( " Data: \( data) " )
176+ }
177+
160178 func shutDown( ) {
161179 NewRelic . shutdown ( )
162180 }
You can’t perform that action at this time.
0 commit comments