-
Notifications
You must be signed in to change notification settings - Fork 0
/
async.cljc
85 lines (70 loc) · 3.35 KB
/
async.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(ns mayu.async
#?(:clj (:require [net.cgrand.macrovich :as macros]
[clojure.core.async]
[clojure.walk
:refer [postwalk]])
:cljs (:require [cljs.core.async]))
#?(:cljs (:require-macros [cljs.core.async]
[mayu.async :refer [go go-loop alt!]])))
#?(:clj
(defmacro go [& forms]
`(~(macros/case :clj 'clojure.core.async/go
:cljs 'cljs.core.async/go)
~@(macros/case :clj (postwalk (fn [form]
(cond
(and (symbol? form)
(= "<!" (name form)))
'clojure.core.async/<!
(and (symbol? form)
(= ">!" (name form)))
'clojure.core.async/>!
(and (symbol? form)
(= "alt!" (name form)))
'clojure.core.async/alt!
:else form))
forms)
:cljs forms))))
#?(:clj
(defmacro go-loop [& forms]
`(~(macros/case :clj 'clojure.core.async/go-loop
:cljs 'cljs.core.async/go-loop)
~@(macros/case :clj (postwalk (fn [form]
(cond
(and (symbol? form)
(= "<!" (name form)))
'clojure.core.async/<!
(and (symbol? form)
(= ">!" (name form)))
'clojure.core.async/>!
(and (symbol? form)
(= "alt!" (name form)))
'clojure.core.async/alt!
:else form))
forms)
:cljs forms))))
#?(:clj
(defmacro alt! [& forms]
`(~(macros/case :clj 'clojure.core.async/alt!
:cljs 'cljs.core.async/alt!) ~@forms)))
(def chan #?(:clj clojure.core.async/chan
:cljs cljs.core.async/chan))
(def put! #?(:clj clojure.core.async/put!
:cljs cljs.core.async/put!))
(def take! #?(:clj clojure.core.async/take!
:cljs cljs.core.async/take!))
(def >! #?(:clj clojure.core.async/>!
:cljs cljs.core.async/>!))
(def <! #?(:clj clojure.core.async/<!
:cljs cljs.core.async/<!))
(def buffer #?(:clj clojure.core.async/buffer
:cljs cljs.core.async/buffer))
(def dropping-buffer #?(:clj clojure.core.async/dropping-buffer
:cljs cljs.core.async/dropping-buffer))
(def sliding-buffer #?(:clj clojure.core.async/sliding-buffer
:cljs cljs.core.async/sliding-buffer))
(def timeout #?(:clj clojure.core.async/timeout
:cljs cljs.core.async/timeout))
(def close! #?(:clj clojure.core.async/close!
:cljs cljs.core.async/close!))
(def alts! #?(:clj clojure.core.async/alts!
:cljs cljs.core.async/alts!))