@@ -143,6 +143,17 @@ return nil for unexpected contexts."
143
143
[^long msecs]
144
144
(timers/timeout msecs))
145
145
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
+
146
157
(defmacro defblockingop
147
158
[op doc arglist & body]
148
159
(let [as (mapv #(list 'quote %) arglist)]
@@ -167,11 +178,11 @@ return nil for unexpected contexts."
167
178
@ret
168
179
(deref p))))
169
180
170
- (defn <!
181
+ (defparkingop <!
171
182
" takes a val from port. Must be called inside a (go ...) block. Will
172
183
return nil if closed. Will park if nothing is available."
173
184
[port]
174
- (assert nil " < ! used not in (go ...) block" ))
185
+ (assert nil " > ! used not in (go ...) block" ))
175
186
176
187
(defn take!
177
188
" Asynchronously takes a val from port, passing to fn1. Will pass nil
@@ -206,7 +217,7 @@ return nil for unexpected contexts."
206
217
@ret
207
218
(deref p))))
208
219
209
- (defn >!
220
+ (defparkingop >!
210
221
" puts a val into port. nil values are not allowed. Must be called
211
222
inside a (go ...) block. Will park if no buffer space is available.
212
223
Returns true unless port is already closed."
@@ -349,7 +360,7 @@ return nil for unexpected contexts."
349
360
@ret
350
361
(deref p))))
351
362
352
- (defn alts!
363
+ (defparkingop alts!
353
364
" Completes at most one of several channel operations. Must be called
354
365
inside a (go ...) block. ports is a vector of channel endpoints,
355
366
which can be either a channel to take from or a vector of
@@ -492,7 +503,9 @@ return nil for unexpected contexts."
492
503
Returns a channel which will receive the result of the body when
493
504
completed"
494
505
[& 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)))
496
509
497
510
(defn thread-call
498
511
" Executes f in another thread, returning immediately to the calling
0 commit comments