Skip to content

Instantly share code, notes, and snippets.

@kitallis
Created March 18, 2025 06:19
Show Gist options
  • Save kitallis/4e964138bfeff991cdb94e4b95b404f3 to your computer and use it in GitHub Desktop.
Save kitallis/4e964138bfeff991cdb94e4b95b404f3 to your computer and use it in GitHub Desktop.
(ns trillain.handler
(:require [clojure.string :as string]
[compojure.core :refer [defroutes GET]]
[compojure.route :as route]
[ring.middleware.defaults :refer [site-defaults wrap-defaults]]))
(defonce store (atom {}))
(defonce job-eta-in-sec 10000)
(defn- job []
(Thread/sleep job-eta-in-sec)
(rand-int 42))
(defn- result [id]
(if-let [work (get @store id)]
(deref work)
(-> store
(swap! assoc id (future (job)))
(get id)
(deref))))
(defn- call [id]
{:status 200 :body (str (result id))})
(defroutes app-routes
(GET "/call" [id] (call id))
(route/not-found "You have reached basically, nowhere."))
(def app (wrap-defaults app-routes site-defaults))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment