feat: add a state

This commit is contained in:
langhuihui
2023-09-10 18:28:15 +08:00
parent 7ff64a914e
commit 8f7ff8d270
4 changed files with 59 additions and 31 deletions

View File

@@ -16,6 +16,7 @@ var znomorereconnect = zap.String("reason", "no more reconnect")
type IPuller interface {
IPublisher
Connect() error
OnConnected()
Disconnect()
Pull() error
Reconnect() bool
@@ -28,6 +29,10 @@ type Puller struct {
ClientIO[config.Pull]
}
func (pub *Puller) OnConnected() {
pub.ReConnectCount = 0 // 重置重连次数
}
// 是否需要重连
func (pub *Puller) Reconnect() (ok bool) {
ok = pub.Config.RePull == -1 || pub.ReConnectCount <= pub.Config.RePull