]> git.giacomolli.uk - onechat/blobdiff - whatsapp.go
Separate returns from longer statement blocks
[onechat] / whatsapp.go
index e02e8c66242c1953091e1a85eeb78b691f9496a0..b0767084a6cb614af20f8dde1da27927f459aa50 100644 (file)
@@ -209,10 +209,10 @@ type WhatsApp struct {
 // failed first connection starts the same outage notice as a lost connection. A
 // timer in the select retries it with a doubled wait from 2 seconds to 5
 // minutes, without a retry goroutine or a wait that blocks commands or the
-// inbox. A connection, unlink, logout, pair command, or ctx end stops retries.
-// The library owns retries after a connection opens. Run returns the error of a
-// write of the log or of the state file, which stops the daemon, because then
-// messages would be lost.
+// inbox. A connection, unlink, logout, or ctx end stops retries. The library
+// owns retries after a connection opens. Run returns the error of a write of
+// the log or of the state file, which stops the daemon, because then messages
+// would be lost.
 func (w *WhatsApp) Run(ctx context.Context, l *TurnLoop, notify func(Event)) error {
        w.mutex.Lock()
        w.notify = notify
@@ -277,13 +277,13 @@ func (w *WhatsApp) Run(ctx context.Context, l *TurnLoop, notify func(Event)) err
                                return err
                        }
                case request := <-w.requests:
-                       stopRetry()
                        cancel()
                        pairing.Wait()
                        cancel = func() {}
 
                        switch {
                        case request.unlink:
+                               stopRetry()
                                err = w.unlink(ctx, l, request.answer)
                                if err != nil {
                                        return err
@@ -459,6 +459,7 @@ func (w *WhatsApp) connect(ctx context.Context) bool {
        if err == nil || ctx.Err() != nil || !w.retrying || !w.linked {
                w.retrying = false
                w.mutex.Unlock()
+
                return false
        }