This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-18
Channels
- # announcements (18)
- # babashka (34)
- # beginners (47)
- # biff (1)
- # calva (99)
- # cider (1)
- # clojure (99)
- # clojure-austin (13)
- # clojure-australia (1)
- # clojure-dev (53)
- # clojure-europe (30)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-spec (7)
- # clojure-uk (1)
- # clojurescript (50)
- # cursive (11)
- # datahike (20)
- # datomic (10)
- # fulcro (7)
- # graalvm (8)
- # gratitude (1)
- # introduce-yourself (7)
- # jackdaw (1)
- # joyride (1)
- # lambdaisland (7)
- # lsp (2)
- # malli (7)
- # nbb (1)
- # off-topic (1)
- # portal (24)
- # re-frame (8)
- # reagent (13)
- # reitit (7)
- # releases (2)
- # remote-jobs (8)
- # rewrite-clj (3)
- # sci (1)
- # scittle (21)
- # shadow-cljs (2)
- # testing (3)
- # tools-deps (22)
- # web-security (19)
Trying to write defmacro will-be
, like clojure.test/is
, that times out after multiple attempts, and produces nice failures like clojure.test/is
(comparing actual & expected).
I have the below attempt, but it’s not a macro and doesn’t produce nice errors. Any ideas, or does this function/macro already exist?
(defn will-be
[f timeout-ms sleep-ms]
(let [start (System/currentTimeMillis)]
(while (not (f))
(when (< (+ start timeout-ms) (System/currentTimeMillis))
(throw (ex-info "will-be timed out" {})))
(Thread/sleep sleep-ms))))
;; for example, (will-be #(= "hello world" @server-response) 1000 100)
I have one drafted on my library Check: https://gitlab.com/mauricioszabo/check/-/blob/await-for-things/src/check/async.clj#L208-239 I'm using Promesa but if instead you throw an exception, maybe it can work for you?
Nice failures are basically by making the await-for
a macro and trying to get what condition was wrong