@@ -11,7 +11,7 @@ public protocol RequestInterceptor {
1111 /// catch and retry a failed request
1212 /// - Returns: nil if the request should not be retried. Otherwise a publisher that will be executed before
1313 /// retrying the request
14- func rescueRequest < Output> ( _ request: Request < Output > , error: Error ) -> AnyPublisher < Void , Error > ?
14+ func shouldRescueRequest < Output> ( _ request: Request < Output > , error: Error ) async throws -> Bool
1515}
1616
1717/// a protocol intercepting a session response
@@ -25,32 +25,3 @@ public protocol ResponseInterceptor {
2525 /// - Parameter request: the request that was sent to the server
2626 func receivedResponse< Output> ( _ result: Result < Output , Error > , for request: Request < Output > )
2727}
28-
29- extension RequestInterceptor {
30- func shouldRescueRequest< Output> ( _ request: Request < Output > , error: Error ) async throws -> Bool {
31- var cancellable : Set < AnyCancellable > = [ ]
32- let onCancel = { cancellable. removeAll ( ) }
33-
34- guard let rescuePublisher = rescueRequest ( request, error: error) else {
35- return false
36- }
37-
38- return try await withTaskCancellationHandler (
39- handler: { onCancel ( ) } ,
40- operation: {
41- try await withCheckedThrowingContinuation { continuation in
42- rescuePublisher
43- . sink (
44- receiveCompletion: {
45- if case let . failure( error) = $0 {
46- return continuation. resume ( throwing: error)
47- }
48- } ,
49- receiveValue: { _ in
50- continuation. resume ( returning: true )
51- } )
52- . store ( in: & cancellable)
53- }
54- } )
55- }
56- }
0 commit comments