@@ -21,22 +21,14 @@ extension REST {
21
21
private let responseHandler : any RESTRustResponseHandler < Success >
22
22
private var networkTask : MullvadApiCancellable ?
23
23
24
- private let retryStrategy : RetryStrategy
25
- private var retryDelayIterator : AnyIterator < Duration >
26
- private var retryTimer : DispatchSourceTimer ?
27
- private var retryCount = 0
28
-
29
24
init (
30
25
name: String ,
31
26
dispatchQueue: DispatchQueue ,
32
- retryStrategy: RetryStrategy ,
33
27
requestHandler: @escaping MullvadApiRequestHandler ,
34
28
responseDecoder: JSONDecoder ,
35
29
responseHandler: some RESTRustResponseHandler < Success > ,
36
30
completionHandler: CompletionHandler ? = nil
37
31
) {
38
- self . retryStrategy = retryStrategy
39
- retryDelayIterator = retryStrategy. makeDelayIterator ( )
40
32
self . responseDecoder = responseDecoder
41
33
self . requestHandler = requestHandler
42
34
self . responseHandler = responseHandler
@@ -53,10 +45,7 @@ extension REST {
53
45
}
54
46
55
47
override public func operationDidCancel( ) {
56
- retryTimer? . cancel ( )
57
48
networkTask? . cancel ( )
58
-
59
- retryTimer = nil
60
49
networkTask = nil
61
50
}
62
51
@@ -76,12 +65,7 @@ extension REST {
76
65
guard let self else { return }
77
66
78
67
if let error = response. restError ( ) {
79
- if response. shouldRetry {
80
- retryRequest ( with: error)
81
- } else {
82
- finish ( result: . failure( error) )
83
- }
84
-
68
+ finish ( result: . failure( error) )
85
69
return
86
70
}
87
71
@@ -97,51 +81,6 @@ extension REST {
97
81
}
98
82
}
99
83
}
100
-
101
- private func retryRequest( with error: REST . Error ) {
102
- // Check if retry count is not exceeded.
103
- guard retryCount < retryStrategy. maxRetryCount else {
104
- if retryStrategy. maxRetryCount > 0 {
105
- logger. debug ( " Ran out of retry attempts ( \( retryStrategy. maxRetryCount) ) " )
106
- }
107
- finish ( result: . failure( error) )
108
- return
109
- }
110
-
111
- // Increment retry count.
112
- retryCount += 1
113
-
114
- // Retry immediately if retry delay is set to never.
115
- guard retryStrategy. delay != . never else {
116
- startRequest ( )
117
- return
118
- }
119
-
120
- guard let waitDelay = retryDelayIterator. next ( ) else {
121
- logger. debug ( " Retry delay iterator failed to produce next value. " )
122
-
123
- finish ( result: . failure( error) )
124
- return
125
- }
126
-
127
- logger. debug ( " Retry in \( waitDelay. logFormat ( ) ) . " )
128
-
129
- // Create timer to delay retry.
130
- let timer = DispatchSource . makeTimerSource ( queue: dispatchQueue)
131
-
132
- timer. setEventHandler { [ weak self] in
133
- self ? . startRequest ( )
134
- }
135
-
136
- timer. setCancelHandler { [ weak self] in
137
- self ? . finish ( result: . failure( OperationError . cancelled) )
138
- }
139
-
140
- timer. schedule ( wallDeadline: . now( ) + waitDelay. timeInterval)
141
- timer. activate ( )
142
-
143
- retryTimer = timer
144
- }
145
84
}
146
85
}
147
86
0 commit comments