Skip to content

Instantly share code, notes, and snippets.

@ifesdjeen
Last active December 21, 2015 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ifesdjeen/6346864 to your computer and use it in GitHub Desktop.
Save ifesdjeen/6346864 to your computer and use it in GitHub Desktop.
Testing with countdown latch
(ns my-test-ns
(:require [clojure.test :refer :all])
(:import [java.util.concurrent CountDownLatch TimeUnit])
(defmacro with-latch
[countdown-from & body]
`(let [latch# (CountDownLatch. ~countdown-from)
~'latch latch#]
~@body
(.await latch# 5 TimeUnit/SECONDS)
(is (= 0 (.getCount latch#)))))
;; Example usage:
(deftest with-latch-test
(with-latch 3
(.countDown latch)
(.countDown latch)
(.countDown latch)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment