Skip to content

Instantly share code, notes, and snippets.

@drewr
Last active December 7, 2025 06:19
Show Gist options
  • Select an option

  • Save drewr/2534a7f6324fb1935d8df35d79a8010b to your computer and use it in GitHub Desktop.

Select an option

Save drewr/2534a7f6324fb1935d8df35d79a8010b to your computer and use it in GitHub Desktop.
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.12.3"}}
:tasks
{:require [[clojure.string :as str]]
test {:doc "Run the test suite."
:task (clojure "-M:test" "-m" "cognitect.test-runner")}
test:bb {:doc "Run the test suite using Babashka to check compatibility."
:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
:task (exec 'cognitect.test-runner.api/test)}
test:all {:doc "Run the test suite with both Clojure and Babashka."
:depends [test test:bb]}
ci {:doc "Run the CI pipeline of tests and build the JAR."
:depends [test:all] ; or just test
:task (clojure "-T:build" "jar")}
ci:deploy {:doc "Run the CI pipeline and deploy the JAR."
:depends [ci]
:task (clojure "-T:build" "deploy")}
install {:doc "Install the JAR locally (build via ci)."
:task (clojure "-T:build" "install")}}}
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.12.3"}
tech.kwik/kwik {:mvn/version "0.10.8"}}
:aliases
{:test
{:extra-paths ["test"]
:extra-deps {org.clojure/test.check {:mvn/version "1.1.2"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}}
:build {:deps {io.github.clojure/tools.build
{:mvn/version "0.10.11"}
slipset/deps-deploy {:mvn/version "0.2.2"}}
:ns-default build}}}
(ns com.draines.quictime
(:import (tech.kwik.core QuicClientConnection)
(java.time Duration)))
(defn head
[url]
(let [c (-> (QuicClientConnection/newBuilder)
(.uri (java.net.URI/create url))
(.applicationProtocol "h3")
(.connectTimeout (Duration/ofSeconds 2))
.build)]
(.connect c)
(let [stream (.createStream c true)]
(println "stream id" (.getStreamId stream))
(with-open [out (.getOutputStream stream)]
(.write out (.getBytes "HEAD / HTTP/3\r\n" "UTF-8"))
(.flush out)
(with-open [in (.getInputStream stream)]
(slurp in))))))
(defn timeout [task-fn timeout-ms]
(let [f (future (try (task-fn)
(catch InterruptedException e
(println "Task interrupted!"))))]
(Thread/sleep timeout-ms)
(if (realized? f)
(println "Task completed before timeout.")
(do
(.interrupt (Thread/currentThread))
(println "Attempting to interrupt task...")))))
(comment
(timeout #(head "https://example.com:443") 3000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment