feat: Add core.async dependency and use chan/go-loop in send! function

This commit is contained in:
2025-06-08 09:02:48 -07:00
committed by niten
parent 16f23cb6da
commit ffb5d50954
+6 -5
View File
@@ -1,6 +1,7 @@
(ns milquetoast.api)
(ns milquetoast.api (ns milquetoast.api
(:require [milquetoast.core :as core] (:require [clojure.core.async :refer [chan <! go-loop]]
[milquetoast.core :as core]
[milquetoast.utils :as utils])) [milquetoast.utils :as utils]))
(defn send! (defn send!
@@ -25,7 +26,7 @@
:or {buffer-size 1 :or {buffer-size 1
qos 1 qos 1
retain false}}] retain false}}]
(let [chan (async/chan buffer-size)] (let [chan (chan buffer-size)]
(core/add-channel! client chan) (core/add-channel! client chan)
(go-loop [msg (<! chan)] (go-loop [msg (<! chan)]
(when msg (when msg
@@ -48,8 +49,8 @@
:as opts}] :as opts}]
(let [broker-uri (str (name scheme) "://" host ":" port)] (let [broker-uri (str (name scheme) "://" host ":" port)]
(core/MilquetoastClient. (core/create-mqtt-client! (assoc opts :broker-uri broker-uri)) (core/MilquetoastClient. (core/create-mqtt-client! (assoc opts :broker-uri broker-uri))
(atom []) (atom [])
verbose))) verbose)))
(defn connect-json! (defn connect-json!
"Connects to an MQTT broker with the provided arguments and configures the client to send and receive JSON messages." "Connects to an MQTT broker with the provided arguments and configures the client to send and receive JSON messages."