-
Notifications
You must be signed in to change notification settings - Fork 1
/
async.clj
35 lines (30 loc) · 830 Bytes
/
async.clj
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
(ns serverless.core.async
(:require [cljs.core.async :as async]))
(defmacro go-try
[& body]
`(let [chan# (async/promise-chan)]
(async/go
(let [result# (try ~@body (catch :default e# e#))]
(if (nil? result#)
(async/close! chan#)
(async/>! chan# result#))))
chan#))
(defmacro <! [ch]
`(if (serverless.core.async/channel? ~ch)
(async/<! ~ch)
~ch))
(defmacro <? [ch]
`(let [val# (serverless.core.async/<! ~ch)]
(if (instance? js/Error val#)
(throw val#)
val#)))
(defmacro <<? [chans]
`(let [res# (atom [])]
(doseq [c# ~chans]
(swap! res# conj (serverless.core.async/<? c#)))
@res#))
(defmacro <<! [chans]
`(let [res# (atom [])]
(doseq [c# ~chans]
(swap! res# conj (serverless.core.async/<! c#)))
@res#))