http-kit what is the difference between sending response through channel and just return a map

StackOverflow https://stackoverflow.com/questions/22830638

  •  26-06-2023
  •  | 
  •  

Question

As the title says. What is the difference between sending response through a channel and just return a map.

(defn handler-one
  [request]
  (response "hello world")

(defn handler-two
  [request]
  (with-channel request channel
    (send! channel (response "hello world"))
Was it helpful?

Solution

handler-one function uses synchronous approach. Request -> Response

handle-two is a way to achieve Request -> Response but asynchronously.

You can check with-channel macro definition for more implementation details (and documentation).

If you want more details about asynchronous approach in general, then I recommend learning about one of: Futures, Reactive Programming, Netty, Node.js or Vert.x

OTHER TIPS

Following the theory of core.async channels, if you use channels you will have non-blocking communication meaning that your thread will not be blocked until the http response. If you use the blocking communication waiting for the map http-response your thread will be blocked

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top