I am lost with all this async / multithreaded libs and native clojure capabilities.
I have a webservice which calls an external API, transforms it response, and gives back to client. Right now is written in Python. I would like to let each client to execute its request in a separate thread so that they don't wait for each other to finish, or the server to be async. There is no heavy calculations involved, only waiting for IO.
I thought this would be easy with clojure but I am missing something... Aleph is async server, right? However, when I simulate a wait
inside request handler, the whole server is waiting, not only the client. So I don't quite see the point of being asynchronous here?
In my understanding, which may be wrong, is that an async server never blocks for IO operations? May be sleep
is a bad mean for simulating waiting for IO?
EDIT I created a dumb waiting service which I invoke from Clojure's Aleph server, and still, the request handling is sequential
(ns aleph-t.core
( :require [aleph.http :as http]
[aleph.netty :as netty]))
(defn heavy [] (Thread/sleep 10000) "hello!")
(defn handler [req]
{:status 200
:headers {"content-type" "text/plain"}
:body (heavy)})
; need to wait otherwise server is closed
(defn -main [& args]
(netty/wait-for-close (http/start-server handler {:port 8080}))
)