Skip to content

Instantly share code, notes, and snippets.

@rschmukler
Created April 19, 2023 14:32
Show Gist options
  • Save rschmukler/314b786206246c906caa6a2f99d731a7 to your computer and use it in GitHub Desktop.
Save rschmukler/314b786206246c906caa6a2f99d731a7 to your computer and use it in GitHub Desktop.
Loom Lock
(defn ppmap
[f coll]
(->> coll
(mapv
(fn [x]
(let [cf (java.util.concurrent.CompletableFuture.)]
(Thread/startVirtualThread
(bound-fn []
(try
(.complete cf (f x))
(catch Exception e
(.completeExceptionally cf e)))))
cf)))
(map deref)))
(let [n 4]
(->> (range n)
(ppmap
(fn [_]
(->> (range n)
(ppmap (fn [_]
(->> (range n)
(ppmap (fn [_]
(ppmap identity (range n))))
(apply concat)
(into #{}))))
(apply concat)
(into #{}))))
(apply concat)
(into #{})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment