Skip to content

Commit b3d0ec5

Browse files
committed
use bound-fn when appropriate to convey bindings
1 parent 1a70432 commit b3d0ec5

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

examples/plumbing_tls_alpn.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@
104104
executor (Executors/newVirtualThreadPerTaskExecutor)
105105
accept-thread
106106
(Thread.
107-
(fn []
107+
(bound-fn []
108108
(while @running
109109
(try
110110
(let [socket (.accept server-socket)]
111111
(.submit executor
112112
^Callable
113-
(fn []
113+
(bound-fn []
114114
(try
115115
(let [^javax.net.ssl.SSLSocket ssl-socket (cast javax.net.ssl.SSLSocket socket)
116116
params (doto (SSLParameters.)

src/ol/clave/impl/http/impl.clj

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,11 @@
231231

232232
(defn then [x f]
233233
(if (instance? CompletableFuture x)
234-
(.thenApply ^CompletableFuture x
235-
^Function (reify Function
236-
(apply [_ args]
237-
(f args))))
234+
(let [bound-f (bound-fn* f)]
235+
(.thenApply ^CompletableFuture x
236+
^Function (reify Function
237+
(apply [_ args]
238+
(bound-f args)))))
238239
(f x)))
239240

240241
(defn- apply-interceptors [init interceptors k]
@@ -363,22 +364,24 @@
363364
interceptors/default-interceptors)))]
364365
(if async
365366
(let [then-fn (:async-then req)
366-
catch-fn (:async-catch req)]
367+
catch-fn (:async-catch req)
368+
bound-then-fn (when then-fn (bound-fn* then-fn))
369+
bound-catch-fn (when catch-fn (bound-fn* catch-fn))]
367370
(cond-> ^CompletableFuture resp
368371
then-fn (.thenApply
369372
(reify Function
370373
(apply [_ resp]
371-
(then-fn resp))))
374+
(bound-then-fn resp))))
372375
catch-fn (.exceptionally
373376
(reify Function
374377
(apply [_ e]
375378
(let [^Throwable e e
376379
cause (ex-cause e)]
377-
(catch-fn {:ex e
378-
:ex-cause cause
379-
:ex-data (ex-data (or cause e))
380-
:ex-message (ex-message (or cause e))
381-
:request req})))))))
380+
(bound-catch-fn {:ex e
381+
:ex-cause cause
382+
:ex-data (ex-data (or cause e))
383+
:ex-message (ex-message (or cause e))
384+
:request req})))))))
382385
resp)))))
383386

384387
(defn request-with-lease
@@ -406,11 +409,12 @@
406409
request-builder)
407410
request (.build request-builder)
408411
http-future (.sendAsync client request (HttpResponse$BodyHandlers/ofInputStream))
412+
watcher-fn (bound-fn* (fn []
413+
(when (deref (lease/done-signal lease))
414+
(.cancel http-future true))))
409415
watcher (CompletableFuture/runAsync
410416
(reify Runnable
411-
(run [_]
412-
(when (deref (lease/done-signal lease))
413-
(.cancel http-future true))))
417+
(run [_] (watcher-fn)))
414418
@shared-virtual-executor)]
415419
(try
416420
(let [response (.get http-future)]

src/ol/clave/storage/file.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265

266266
(defn- start-lock-freshener! [^Path filename]
267267
(Thread/startVirtualThread
268-
(fn []
268+
(bound-fn []
269269
(loop []
270270
(let [result (try
271271
(Thread/sleep (long (.toMillis ^Duration lock-freshness-interval)))

0 commit comments

Comments
 (0)