Exponential backoff retry logic
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

retry: add README content — usage examples, API overview

+36 -4
+36 -4
README.md
··· 1 - ## Retry - Generic retry logic with exponential backoff 1 + ## Retry -- Generic retry logic with exponential backoff 2 2 3 - Provides configurable retry logic with exponential backoff, jitter, and customizable predicates for determining when to retry operations. 3 + Provides configurable retry logic with exponential backoff, jitter, and 4 + customizable predicates for determining when to retry operations. 4 5 5 6 ## Installation 6 7 7 - `opam install retry` will install this library. 8 + ``` 9 + opam install retry 10 + ``` 8 11 9 - ## Documentation 12 + ## Usage 10 13 14 + ```ocaml 15 + let config = Retry.config ~max_retries:5 () in 16 + let should_retry = function 17 + | Eio.Net.Connection_refused _ -> true 18 + | _ -> false 19 + in 20 + Retry.with_retry ~clock ~config ~should_retry (fun () -> 21 + connect_to_server ()) 22 + ``` 23 + 24 + For result-returning functions: 25 + 26 + ```ocaml 27 + Retry.with_retry_result ~clock ~config 28 + ~should_retry:(fun `Unavailable -> true | _ -> false) 29 + (fun () -> call_api ()) 30 + ``` 31 + 32 + ## API 33 + 34 + - `Retry.config` -- Create config (`?max_retries`, `?backoff_factor`, `?backoff_max`, `?jitter`) 35 + - `Retry.default_config` -- 3 retries, 0.3s backoff, 120s max, jitter on 36 + - `Retry.with_retry` -- Retry on exception 37 + - `Retry.with_retry_result` -- Retry on error result 38 + - `Retry.calculate_backoff` -- Compute delay for a given attempt 39 + 40 + ## Licence 41 + 42 + MIT