Created
June 8, 2022 08:18
-
-
Save henryw374/4517d76b925d6da2134536fecf17dcb9 to your computer and use it in GitHub Desktop.
clojure executorservice concurrency testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns same-thread-executor | |
"handy in unit tests to have things happen straight away" | |
(:import (java.util.concurrent ExecutorService Future))) | |
(defn executor [] | |
(reify ExecutorService | |
(^Future submit [_ ^Callable f] | |
(let [r (f)] | |
(reify Future | |
(get [_] r)))))) | |
(comment | |
@(.submit (executor) (fn [] "yay")) | |
;=> "yay" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment