Skip to content

Commit

Permalink
Fix jdk17 compatibility issue with pu/close! impl
Browse files Browse the repository at this point in the history
  • Loading branch information
niwinz committed Aug 19, 2024
1 parent 0c5ed6a commit a546283
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/promesa/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
java.util.concurrent.CompletionStage
java.util.concurrent.CountDownLatch
java.util.concurrent.ExecutionException
java.util.concurrent.TimeUnit
java.util.concurrent.TimeoutException
java.util.concurrent.locks.ReentrantLock)))

Expand Down Expand Up @@ -176,9 +177,25 @@
(extend-protocol pt/ICloseable
java.util.concurrent.ExecutorService
(-closed? [it]
(.isShutdown it))
(.isTerminated it))
(-close! [it]
(.close ^java.lang.AutoCloseable it))
(let [interrupted (volatile! false)]
(loop [terminated? ^Boolean (.isTerminated it)]
(when-not terminated?
(.shutdown it)
(let [terminated?
(try
(.awaitTermination it 1 TimeUnit/DAYS)
(catch InterruptedException cause
(when-not @interrupted
(vreset! interrupted true)
(.shutdownNow it))
terminated?))]
(recur ^Boolean terminated?))))

(when @interrupted
(let [thread (Thread/currentThread)]
(.interrupt thread)))))

java.lang.AutoCloseable
(-closed? [_]
Expand Down

0 comments on commit a546283

Please sign in to comment.