@@ -462,43 +462,41 @@ to catch and handle."
462
462
[& body]
463
463
(#'clojure.core.async.impl.go/go-impl &env body))
464
464
465
- (defn thread-call-impl
466
- [f workload]
467
- (let [c (chan 1 )]
468
- (let [binds (Var/getThreadBindingFrame )]
469
- (dispatch/exec
470
- (fn []
471
- (Var/resetThreadBindingFrame binds)
472
- (try
473
- (let [ret (f )]
474
- (when-not (nil? ret)
475
- (>!! c ret)))
476
- (finally
477
- (close! c))))
478
- workload))
479
- c))
465
+ (defn returning-chan [f c]
466
+ (fn []
467
+ (try
468
+ (let [ret (f )]
469
+ (when-not (nil? ret)
470
+ (>!! c ret)))
471
+ (finally (close! c)))))
480
472
481
473
(defn thread-call
482
474
" Executes f in another thread, returning immediately to the calling
483
475
thread. Returns a channel which will receive the result of calling
484
476
f when completed, then close."
485
477
[f]
486
- (thread-call-impl f :mixed ))
478
+ (let [c (chan 1 )]
479
+ (-> f bound-fn* (returning-chan c) (dispatch/exec :mixed ))
480
+ c))
487
481
488
482
(defmacro thread
489
483
" Executes the body in another thread, returning immediately to the
490
484
calling thread. Returns a channel which will receive the result of
491
485
the body when completed, then close."
492
486
[& body]
493
- `(thread-call-impl (^:once fn* [] ~@body) :mixed ))
487
+ `(let [c# (chan 1 )]
488
+ (-> (^:once fn* [] ~@body) bound-fn* (returning-chan c#) (dispatch/exec :mixed ))
489
+ c#))
494
490
495
491
(defmacro io-thread
496
492
" Executes the body in a thread intended for blocking I/O workloads,
497
493
returning immediately to the calling thread. The body must not do
498
494
extended computation (if so, use 'thread' instead). Returns a channel
499
495
which will receive the result of the body when completed, then close."
500
496
[& body]
501
- `(thread-call-impl (^:once fn* [] ~@body) :io ))
497
+ `(let [c# (chan 1 )]
498
+ (-> (^:once fn* [] ~@body) bound-fn* (returning-chan c#) (dispatch/exec :io ))
499
+ c#))
502
500
503
501
; ;;;;;;;;;;;;;;;;;;; ops ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
504
502
0 commit comments