Skip to content

Commit 9496984

Browse files
ecksunLinus Wallgren
authored andcommitted
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.
1 parent 5208ce8 commit 9496984

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ may lead to messages being silently dropped.
129129
* `persistence` - Defaults to false (messages will not survive a broker restart)
130130
* `max_keepalive` - defaults to 65535 and, from version 2.0.12, `SetKeepAlive(0)` will result in a rejected connection
131131
by default.
132+
* `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.
132133

133134
Reporting bugs
134135
--------------

token.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ type PacketAndToken struct {
3737
type Token interface {
3838
// Wait will wait indefinitely for the Token to complete, ie the Publish
3939
// to be sent and confirmed receipt from the broker.
40+
//
41+
// Note that, for backward compatibility, if the client reconnects to the
42+
// broker Wait() will return before the message is delivered
4043
Wait() bool
4144

4245
// WaitTimeout takes a time.Duration to wait for the flow associated with the
4346
// Token to complete, returns true if it returned before the timeout or
4447
// returns false if the timeout occurred. In the case of a timeout the Token
4548
// does not have an error set in case the caller wishes to wait again.
49+
//
50+
// Note that, for backward compatibility, if the client reconnects to the
51+
// broker Wait() will return before the message is delivered
4652
WaitTimeout(time.Duration) bool
4753

4854
// Done returns a channel that is closed when the flow associated
@@ -51,6 +57,9 @@ type Token interface {
5157
//
5258
// Done is provided for use in select statements. Simple use cases may
5359
// use Wait or WaitTimeout.
60+
//
61+
// Note that, for backward compatibility, if the client reconnects to the
62+
// broker Wait() will return before the message is delivered
5463
Done() <-chan struct{}
5564

5665
Error() error

0 commit comments

Comments
 (0)