You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Network.HTTP.Affjax.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -150,7 +150,7 @@ Makes a `DELETE` request to the specified URL and ignores the response.
150
150
retry :: forall e a b. (Requestable a) => Maybe Int -> (AffjaxRequest a -> Affjax (avar :: AVAR | e) b) -> AffjaxRequest a -> Affjax (avar :: AVAR | e) b
151
151
```
152
152
153
-
Retry a request with exponential backoff, timing out optionally after a specified number of milliseconds.
153
+
Retry a request with exponential backoff, timing out optionally after a specified number of milliseconds. After the timeout, the last received response is returned; if it was not possible to communicate with the server due to an error, then this is bubbled up.
@@ -123,9 +124,13 @@ delete u = affjax $ defaultRequest { method = DELETE, url = u }
123
124
delete_::foralle. URL->AffjaxeUnit
124
125
delete_ = delete
125
126
126
-
-- | Retry a request with exponential backoff, timing out optionally after a specified number of milliseconds.
127
+
-- | Either we have a failure (which may be an exception or a failed response), or we have a successful response.
128
+
typeRetryStateea=Either (Eitherea) a
129
+
130
+
-- | Retry a request with exponential backoff, timing out optionally after a specified number of milliseconds. After the timeout, the last received response is returned; if it was not possible to communicate with the server due to an error, then this is bubbled up.
127
131
retry::foralleab. (Requestablea) =>MaybeInt-> (AffjaxRequesta->Affjax (avar::AVAR | e) b) -> (AffjaxRequesta->Affjax (avar::AVAR | e) b)
128
132
retry milliseconds run req = do
133
+
-- failureVar is either an exception or a failed request
129
134
failureVar <- makeVar
130
135
let loop = go failureVar
131
136
case milliseconds of
@@ -139,26 +144,29 @@ retry milliseconds run req = do
139
144
loopHandle `cancel` error "Cancel"
140
145
result <- takeVar respVar
141
146
case result of
142
-
Nothing->
143
-
takeVar failureVar
147
+
Nothing-> takeVar failureVar >>= either throwError pure
144
148
Just resp -> pure resp
145
149
where
146
-
assert200 resp =
150
+
-- delay at attempt #n with exponential backoff
151
+
delay n = round $ max maxDelay $ 100.0 * (pow 2.0 $ toNumber (n - 1))
152
+
where
153
+
-- maximum delay in milliseconds
154
+
maxDelay = 30.0 * 1000.0
155
+
156
+
retryState::Either__->RetryState__
157
+
retryState (Left exn) = Left $ Left exn
158
+
retryState (Right resp) =
147
159
case resp.status of
148
160
StatusCode200->Right resp
149
-
_ ->Left resp
150
-
151
-
-- maximum delay in milliseconds
152
-
maxDelay = 30.0 * 1000.0
161
+
_ ->Left (Right resp)
153
162
154
163
go failureVar n = do
155
-
result <- run req
156
-
case assert200 result of
157
-
Right b -> pure b
158
-
Left resp ->do
159
-
putVar failureVar resp
160
-
let delay = round $ max maxDelay $ 100.0 * (pow 2.0 $ toNumber (n - 1))
0 commit comments