@@ -29,39 +29,45 @@ final class DataLoader: NSObject, URLSessionDataDelegate, URLSessionDownloadDele
2929 } ( )
3030
3131 func startDataTask( _ task: URLSessionDataTask , session: URLSession , delegate: URLSessionDataDelegate ? ) async throws -> Response < Data > {
32- try await withTaskCancellationHandler ( handler : { task . cancel ( ) } ) {
32+ try await withTaskCancellationHandler ( operation : {
3333 try await withUnsafeThrowingContinuation { continuation in
3434 let handler = DataTaskHandler ( delegate: delegate)
3535 handler. completion = continuation. resume ( with: )
3636 self . handlers [ task] = handler
3737
3838 task. resume ( )
3939 }
40- }
40+ } , onCancel: {
41+ task. cancel ( )
42+ } )
4143 }
4244
4345 func startDownloadTask( _ task: URLSessionDownloadTask , session: URLSession , delegate: URLSessionDownloadDelegate ? ) async throws -> Response < URL > {
44- try await withTaskCancellationHandler ( handler : { task . cancel ( ) } ) {
46+ try await withTaskCancellationHandler ( operation : {
4547 try await withUnsafeThrowingContinuation { continuation in
4648 let handler = DownloadTaskHandler ( delegate: delegate)
4749 handler. completion = continuation. resume ( with: )
4850 self . handlers [ task] = handler
4951
5052 task. resume ( )
5153 }
52- }
54+ } , onCancel: {
55+ task. cancel ( )
56+ } )
5357 }
5458
5559 func startUploadTask( _ task: URLSessionUploadTask , session: URLSession , delegate: URLSessionTaskDelegate ? ) async throws -> Response < Data > {
56- try await withTaskCancellationHandler ( handler : { task . cancel ( ) } ) {
60+ try await withTaskCancellationHandler ( operation : {
5761 try await withUnsafeThrowingContinuation { continuation in
5862 let handler = DataTaskHandler ( delegate: delegate)
5963 handler. completion = continuation. resume ( with: )
6064 self . handlers [ task] = handler
6165
6266 task. resume ( )
6367 }
64- }
68+ } , onCancel: {
69+ task. cancel ( )
70+ } )
6571 }
6672
6773 // MARK: - URLSessionDelegate
0 commit comments