@@ -29,16 +29,22 @@ For detailed information on each policy's behavior and configuration options, se
2929``` clj
3030(require '[failsage.core :as fs])
3131
32- ; ; Create a retry policy
32+ ; ; Simplest form - no executor needed
33+ (fs/execute
34+ (call-unreliable-service ))
35+
36+ ; ; With a retry policy
3337(def retry-policy
3438 (fs/retry {:max-retries 3
3539 :delay-ms 100
3640 :backoff-delay-factor 2.0 }))
3741
38- ; ; Create an executor with the policy
39- (def executor (fs/executor retry-policy))
42+ ; ; Pass policy directly - no need to create executor
43+ (fs/execute retry-policy
44+ (call-unreliable-service ))
4045
41- ; ; Execute with automatic retry on failure
46+ ; ; Or create an executor explicitly
47+ (def executor (fs/executor retry-policy))
4248(fs/execute executor
4349 (call-unreliable-service ))
4450```
@@ -54,9 +60,8 @@ For detailed information on each policy's behavior and configuration options, se
5460 :backoff-max-delay-ms 5000
5561 :backoff-delay-factor 2.0 }))
5662
57- (def executor (fs/executor retry-policy))
58-
59- (fs/execute executor
63+ ; ; Pass policy directly
64+ (fs/execute retry-policy
6065 (http/get " https://api.example.com/data" ))
6166```
6267
@@ -69,9 +74,8 @@ For detailed information on each policy's behavior and configuration options, se
6974 :on-open-fn (fn [e] (log/warn " Circuit breaker opened!" ))
7075 :on-close-fn (fn [e] (log/info " Circuit breaker closed!" ))}))
7176
72- (def executor (fs/executor circuit-breaker))
73-
74- (fs/execute executor
77+ ; ; Pass policy directly
78+ (fs/execute circuit-breaker
7579 (call-flaky-service ))
7680```
7781
@@ -82,10 +86,8 @@ For detailed information on each policy's behavior and configuration options, se
8286 (fs/fallback {:result {:status :degraded :data []}
8387 :handle-exception Exception}))
8488
85- (def executor (fs/executor fallback-policy))
86-
8789; ; Returns fallback value on any exception
88- (fs/execute executor
90+ (fs/execute fallback-policy
8991 (fetch-user-data user-id))
9092; ; => {:status :degraded :data []}
9193```
@@ -97,9 +99,8 @@ For detailed information on each policy's behavior and configuration options, se
9799 (fs/timeout {:timeout-ms 5000 ; ; 5 second timeout
98100 :interrupt true })) ; ; Interrupt thread on timeout
99101
100- (def executor (fs/executor timeout-policy))
101-
102- (fs/execute executor
102+ ; ; Pass policy directly
103+ (fs/execute timeout-policy
103104 (slow-database-query ))
104105```
105106
@@ -112,9 +113,8 @@ For detailed information on each policy's behavior and configuration options, se
112113 :period-ms 1000
113114 :burst true }))
114115
115- (def executor (fs/executor rate-limiter))
116-
117- (fs/execute executor
116+ ; ; Pass policy directly
117+ (fs/execute rate-limiter
118118 (process-request request))
119119```
120120
@@ -126,9 +126,8 @@ For detailed information on each policy's behavior and configuration options, se
126126 (fs/bulkhead {:max-concurrency 10
127127 :max-wait-time-ms 1000 })) ; ; Wait up to 1 second for permit
128128
129- (def executor (fs/executor bulkhead-policy))
130-
131- (fs/execute executor
129+ ; ; Pass policy directly
130+ (fs/execute bulkhead-policy
132131 (process-task task))
133132```
134133
@@ -183,16 +182,54 @@ Failsage integrates with [futurama](https://github.com/k13labs/futurama) for asy
183182(require '[failsage.core :as fs])
184183(require '[futurama.core :as f])
185184
185+ ; ; Simplest form - uses default thread pool
186+ (fs/execute-async
187+ (f/async
188+ (let [result (f/<!< (async-http-call ))]
189+ (process-result result))))
190+
191+ ; ; With a policy
186192(def retry-policy (fs/retry {:max-retries 3 }))
187- (def executor (fs/executor :io retry-policy)) ; ; Use :io thread pool
193+ (fs/execute-async retry-policy
194+ (f/async
195+ (let [result (f/<!< (async-http-call ))]
196+ (process-result result))))
188197
189- ; ; Returns immediately, executes asynchronously
198+ ; ; With explicit executor and thread pool
199+ (def executor (fs/executor :io retry-policy)) ; ; Use :io thread pool
190200(fs/execute-async executor
191201 (f/async
192202 (let [result (f/<!< (async-http-call ))]
193203 (process-result result))))
194204```
195205
206+ ## Accessing Execution Context
207+
208+ You can access execution context information (like attempt count, start time, etc.) by providing a context binding:
209+
210+ ``` clj
211+ ; ; Synchronous execution with context
212+ (def retry-policy (fs/retry {:max-retries 3 }))
213+
214+ (fs/execute retry-policy ctx
215+ (let [attempt (.getAttemptCount ctx)
216+ start-time (.getStartTime ctx)]
217+ (log/info " Attempt" attempt " started at" start-time)
218+ (call-service )))
219+
220+ ; ; Asynchronous execution with context
221+ (fs/execute-async retry-policy ctx
222+ (f/async
223+ (log/info " Async attempt" (.getAttemptCount ctx))
224+ (f/<!< (async-call-service ))))
225+ ```
226+
227+ The context object provides access to:
228+ - ` .getAttemptCount ` - Current attempt number (0-indexed)
229+ - ` .getStartTime ` - When execution started
230+ - ` .getElapsedTime ` - Time elapsed since execution started
231+ - And more - see [ ExecutionContext] ( https://failsafe.dev/javadoc/core/dev/failsafe/ExecutionContext.html ) / [ AsyncExecution] ( https://failsafe.dev/javadoc/core/dev/failsafe/AsyncExecution.html ) docs
232+
196233## Event Callbacks
197234
198235All policies support event callbacks for observability:
0 commit comments