Skip to content

Commit

Permalink
Document token.Wait behaviour during reconnect
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ecksun authored and Linus Wallgren committed Dec 6, 2021
1 parent 5208ce8 commit 9496984
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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
--------------
Expand Down
9 changes: 9 additions & 0 deletions token.go
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9496984

Please sign in to comment.