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
Expresses a policy for retrying Affjax requests with backoff.
154
+
155
+
#### `defaultRetryPolicy`
156
+
157
+
```purescript
158
+
defaultRetryPolicy :: RetryPolicy
159
+
```
160
+
161
+
A sensible default for retries: no timeout, maximum delay of 30s, initial delay of 0.1s, exponential backoff, and no status code triggers a retry.
162
+
147
163
#### `retry`
148
164
149
165
```purescript
150
-
retry :: forall e a b. (Requestable a) => Maybe Int -> (AffjaxRequest a -> Affjax (avar :: AVAR | e) b) -> AffjaxRequest a -> Affjax (avar :: AVAR | e) b
166
+
retry :: forall e a b. (Requestable a) => RetryPolicy -> (AffjaxRequest a -> Affjax (avar :: AVAR | e) b) -> AffjaxRequest a -> Affjax (avar :: AVAR | e) b
151
167
```
152
168
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.
169
+
Retry a request using a `RetryPolicy`. 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.
Copy file name to clipboardExpand all lines: src/Network/HTTP/Affjax.purs
+32-14Lines changed: 32 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ module Network.HTTP.Affjax
10
10
, post, post_, post', post_'
11
11
, put, put_, put', put_'
12
12
, delete, delete_
13
+
, RetryPolicy(..)
14
+
, defaultRetryPolicy
13
15
, retry
14
16
) where
15
17
@@ -124,48 +126,64 @@ delete u = affjax $ defaultRequest { method = DELETE, url = u }
124
126
delete_::foralle. URL->AffjaxeUnit
125
127
delete_ = delete
126
128
129
+
-- | A sequence of retry delays, in milliseconds.
130
+
typeRetryDelayCurve=Int->Int
131
+
132
+
-- | Expresses a policy for retrying Affjax requests with backoff.
133
+
typeRetryPolicy
134
+
={timeout::MaybeInt-- ^ the timeout in milliseconds, optional
135
+
, delayCurve::RetryDelayCurve
136
+
, shouldRetryWithStatusCode::StatusCode->Boolean-- ^ whether a non-200 status code should trigger a retry
137
+
}
138
+
139
+
-- | A sensible default for retries: no timeout, maximum delay of 30s, initial delay of 0.1s, exponential backoff, and no status code triggers a retry.
-- | Either we have a failure (which may be an exception or a failed response), or we have a successful response.
128
148
typeRetryStateea=Either (Eitherea) a
129
149
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.
131
-
retry::foralleab. (Requestablea) =>MaybeInt-> (AffjaxRequesta->Affjax (avar::AVAR | e) b) -> (AffjaxRequesta->Affjax (avar::AVAR | e) b)
132
-
retry milliseconds run req = do
150
+
-- | Retry a request using a `RetryPolicy`. 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.
151
+
retry::foralleab. (Requestablea) =>RetryPolicy-> (AffjaxRequesta->Affjax (avar::AVAR | e) b) -> (AffjaxRequesta->Affjax (avar::AVAR | e) b)
152
+
retry policy run req = do
133
153
-- failureVar is either an exception or a failed request
0 commit comments