File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 16
16
java.util.concurrent.CompletionStage
17
17
java.util.concurrent.CountDownLatch
18
18
java.util.concurrent.ExecutionException
19
+ java.util.concurrent.TimeUnit
19
20
java.util.concurrent.TimeoutException
20
21
java.util.concurrent.locks.ReentrantLock)))
21
22
176
177
(extend-protocol pt/ICloseable
177
178
java.util.concurrent.ExecutorService
178
179
(-closed? [it]
179
- (.isShutdown it))
180
+ (.isTerminated it))
180
181
(-close! [it]
181
- (.close ^java.lang.AutoCloseable it))
182
+ (let [interrupted (volatile! false )]
183
+ (loop [terminated? ^Boolean (.isTerminated it)]
184
+ (when-not terminated?
185
+ (.shutdown it)
186
+ (let [terminated?
187
+ (try
188
+ (.awaitTermination it 1 TimeUnit/DAYS)
189
+ (catch InterruptedException cause
190
+ (when-not @interrupted
191
+ (vreset! interrupted true )
192
+ (.shutdownNow it))
193
+ terminated?))]
194
+ (recur ^Boolean terminated?))))
195
+
196
+ (when @interrupted
197
+ (let [thread (Thread/currentThread )]
198
+ (.interrupt thread)))))
182
199
183
200
java.lang.AutoCloseable
184
201
(-closed? [_]
You can’t perform that action at this time.
0 commit comments