From 6eb33f54a9671c49c122845fa08f843bf8c41b42 Mon Sep 17 00:00:00 2001 From: Linus Date: Mon, 6 Dec 2021 21:39:22 +0100 Subject: [PATCH] Document token.Wait behaviour during reconnect When a connection is lost to the broker and later resumed the token returned to the user will be considered completed and a new token will be created instead. The result of this is that there is no way for a user of this library to know whether a message has been delivered in the presence of connection issues. Signed-off-by: Linus --- README.md | 1 + token.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index bb1060b..ca5f4b1 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ may lead to messages being silently dropped. * `persistence` - Defaults to false (messages will not survive a broker restart) * `max_keepalive` - defaults to 65535 and, from version 2.0.12, `SetKeepAlive(0)` will result in a rejected connection by default. +* `token.Wait()` - Will return successfully before a message has been delivered if the client needs to reconnect to the broker before the message has been delivered. Reporting bugs -------------- diff --git a/token.go b/token.go index 996ab5b..18feb5f 100644 --- a/token.go +++ b/token.go @@ -37,12 +37,18 @@ type PacketAndToken struct { type Token interface { // Wait will wait indefinitely for the Token to complete, ie the Publish // to be sent and confirmed receipt from the broker. + // + // Note that, for backward compatibility, if the client reconnects to the + // broker Wait() will return before the message is delivered Wait() bool // WaitTimeout takes a time.Duration to wait for the flow associated with the // Token to complete, returns true if it returned before the timeout or // returns false if the timeout occurred. In the case of a timeout the Token // does not have an error set in case the caller wishes to wait again. + // + // Note that, for backward compatibility, if the client reconnects to the + // broker Wait() will return before the message is delivered WaitTimeout(time.Duration) bool // Done returns a channel that is closed when the flow associated @@ -51,6 +57,9 @@ type Token interface { // // Done is provided for use in select statements. Simple use cases may // use Wait or WaitTimeout. + // + // Note that, for backward compatibility, if the client reconnects to the + // broker Wait() will return before the message is delivered Done() <-chan struct{} Error() error