Skip to content

Commit 45c828a

Browse files
authored
Merge pull request #622 from clj-commons/improve-wrap-future
Improve short-circuiting behavior of `wrap-future`
2 parents be2006c + 66effad commit 45c828a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/aleph/netty.clj

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,19 @@
240240
(defn wrap-future
241241
[^Future f]
242242
(when f
243-
(if (.isSuccess f)
244-
(d/success-deferred (.getNow f) nil)
245-
(let [d (d/deferred nil)
246-
;; Ensure the same bindings are installed on the Netty thread (vars,
247-
;; classloader) than the thread registering the
248-
;; `operationComplete` callback.
249-
bound-operation-complete (bound-fn* operation-complete)]
250-
(.addListener f
251-
(reify GenericFutureListener
252-
(operationComplete [_ _]
253-
(ensure-dynamic-classloader)
254-
(bound-operation-complete f d))))
255-
d))))
243+
(let [d (d/deferred nil)]
244+
(if (.isDone f)
245+
(operation-complete f d)
246+
;; Ensure the same bindings are installed on the Netty thread (vars,
247+
;; classloader) than the thread registering the
248+
;; `operationComplete` callback.
249+
(let [bound-operation-complete (bound-fn* operation-complete)]
250+
(.addListener f
251+
(reify GenericFutureListener
252+
(operationComplete [_ _]
253+
(ensure-dynamic-classloader)
254+
(bound-operation-complete f d))))))
255+
d)))
256256

257257
(defn allocate [x]
258258
(if (instance? Channel x)

0 commit comments

Comments
 (0)