From 0a312b4f40515f9230c800651c430164b979c236 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Mon, 11 Jul 2016 16:48:40 -0700 Subject: [PATCH] Add an async and async testing framework. This is a well-worn idea: use a `promise-channel` of `[result nil]` or `[nil error]` pairs. The `go-pair` and `! pc-chan# [(do ~@body) nil]) + (catch js/Error ex# + (cljs.core.async/>! pc-chan# [nil ex#])))) + pc-chan#) + (let [pc-chan# (clojure.core.async/promise-chan)] + (clojure.core.async/go + (try + (clojure.core.async/>! pc-chan# [(do ~@body) nil]) + (catch Exception ex# + (clojure.core.async/>! pc-chan# [nil ex#])))) + pc-chan#))) + +;; Thanks to David Nolen for the name of this macro! http://swannodette.github.io/2013/08/31/asynchronous-error-handling/. +;; This version works a bit differently, though. This must be a macro, so that the enclosed + (datomish.pair-chan/go-pair ~@body) + (cljs.core.async/take! (fn [v# e#] + (cljs.test/is (= e# nil)) + (done#)))))) + (clojure.test/deftest + ~(with-meta name {:async true}) + (let [[v# e#] (clojure.core.async/