feat: Add core.async dependency and use chan/go-loop in send! function
This commit is contained in:
@@ -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."
|
||||||
|
|||||||
Reference in New Issue
Block a user