@@ -143,6 +143,17 @@ return nil for unexpected contexts."
143143 [^long msecs]
144144 (timers/timeout msecs))
145145
146+ (defmacro defparkingop
147+ [op doc arglist & body]
148+ (let [as (mapv #(list 'quote %) arglist)
149+ delegate (-> op name (str " !" ) symbol)]
150+ `(def ~(with-meta op {:arglists `(list ~as) :doc doc})
151+ (if (dispatch/targetting-vthreads? )
152+ (fn [~'& ~'args]
153+ ~(list* apply delegate '[args]))
154+ (fn ~arglist
155+ ~@body)))))
156+
146157(defmacro defblockingop
147158 [op doc arglist & body]
148159 (let [as (mapv #(list 'quote %) arglist)]
@@ -167,11 +178,11 @@ return nil for unexpected contexts."
167178 @ret
168179 (deref p))))
169180
170- (defn <!
181+ (defparkingop <!
171182 " takes a val from port. Must be called inside a (go ...) block. Will
172183 return nil if closed. Will park if nothing is available."
173184 [port]
174- (assert nil " < ! used not in (go ...) block" ))
185+ (assert nil " > ! used not in (go ...) block" ))
175186
176187(defn take!
177188 " Asynchronously takes a val from port, passing to fn1. Will pass nil
@@ -206,7 +217,7 @@ return nil for unexpected contexts."
206217 @ret
207218 (deref p))))
208219
209- (defn >!
220+ (defparkingop >!
210221 " puts a val into port. nil values are not allowed. Must be called
211222 inside a (go ...) block. Will park if no buffer space is available.
212223 Returns true unless port is already closed."
@@ -349,7 +360,7 @@ return nil for unexpected contexts."
349360 @ret
350361 (deref p))))
351362
352- (defn alts!
363+ (defparkingop alts!
353364 " Completes at most one of several channel operations. Must be called
354365 inside a (go ...) block. ports is a vector of channel endpoints,
355366 which can be either a channel to take from or a vector of
@@ -492,7 +503,9 @@ return nil for unexpected contexts."
492503 Returns a channel which will receive the result of the body when
493504 completed"
494505 [& body]
495- (#'clojure.core.async.impl.go/go-impl &env body))
506+ (if (dispatch/targetting-vthreads? )
507+ `(thread-call (^:once fn* [] ~@body) :io )
508+ (#'clojure.core.async.impl.go/go-impl &env body)))
496509
497510(defn thread-call
498511 " Executes f in another thread, returning immediately to the calling
0 commit comments