From 66ca2aa66ae37a099222ebb0acd0fed643ae76a2 Mon Sep 17 00:00:00 2001 From: Steve Dodd Date: Fri, 9 Feb 2024 18:26:17 +0000 Subject: [PATCH] Add isErrored() function so we can tell if the context / connection is in the "errored" state, as may occur if the initial TCP connection fails. --- nmqtt.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nmqtt.nim b/nmqtt.nim index f2eb009..3a62037 100644 --- a/nmqtt.nim +++ b/nmqtt.nim @@ -1209,6 +1209,11 @@ proc unsubscribe*(ctx: MqttCtx, topic: string): Future[void] = ctx.workQueue[msgId] = Work(wk: SubWork, msgId: msgId, topic: topic, typ: Unsubscribe) result = ctx.work() +proc isErrored*(ctx: MqttCtx): bool = + ## Returns true, if the context is in an error state + if ctx.state == Error: + result = true + proc isConnected*(ctx: MqttCtx): bool = ## Returns true, if the client is connected to the broker. if ctx.state == Connected: