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 {
43
43
options. append ( UtilOption ( title: " Notice Network Request " , handler: { [ self ] in noticeNWRequest ( ) } ) )
44
44
options. append ( UtilOption ( title: " Notice Network Failure " , handler: { [ self ] in noticeFailedNWRequest ( ) } ) )
45
45
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
+
46
52
options. append ( UtilOption ( title: " Shut down New Relic Agent " , handler: { [ self ] in shutDown ( ) } ) )
47
53
}
48
54
@@ -157,6 +163,18 @@ class UtilViewModel {
157
163
dataTask. resume ( )
158
164
}
159
165
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
+
160
178
func shutDown( ) {
161
179
NewRelic . shutdown ( )
162
180
}
You can’t perform that action at this time.
0 commit comments