Skip to content

Commit

Permalink
Add isErrored() function so we can tell if the context / connection
Browse files Browse the repository at this point in the history
is in the "errored" state, as may occur if the initial TCP connection
fails.
  • Loading branch information
srd424 committed Feb 9, 2024
1 parent 2bc6c76 commit 66ca2aa
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nmqtt.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 66ca2aa

Please sign in to comment.