正如标题所说。通过通道发送响应和只返回地图有什么区别。
(defn handler-one
[request]
(response "hello world")
(defn handler-two
[request]
(with-channel request channel
(send! channel (response "hello world"))
handler-one
函数使用同步方法。请求 -> 响应
handle-two
是一种异步实现 Request -> Response 的方法。
您可以检查with-channel宏定义以获取更多实现细节(和文档)。
如果您想了解更多关于一般异步方法的详细信息,那么我建议您学习以下之一:Futures、Reactive Programming、Netty、Node.js 或 Vert.x
遵循 core.async 通道的理论,如果您使用通道,您将拥有非阻塞通信,这意味着您的线程在 http 响应之前不会被阻塞。如果您使用阻塞通信等待映射 http-response,您的线程将被阻塞