Merge pull request #64 from DevEverything01/fix/heartbeat-service-start-bug

fix(heartbeat): resolve bug where service could never start
This commit is contained in:
lxowalle 2026-02-12 22:59:50 +08:00 committed by GitHub
commit a8cd784636
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,6 +14,7 @@ type HeartbeatService struct {
interval time.Duration
enabled bool
mu sync.RWMutex
started bool
stopChan chan struct{}
}
@ -31,7 +32,7 @@ func (hs *HeartbeatService) Start() error {
hs.mu.Lock()
defer hs.mu.Unlock()
if hs.running() {
if hs.started {
return nil
}
@ -39,6 +40,7 @@ func (hs *HeartbeatService) Start() error {
return fmt.Errorf("heartbeat service is disabled")
}
hs.started = true
go hs.runLoop()
return nil
@ -48,10 +50,11 @@ func (hs *HeartbeatService) Stop() {
hs.mu.Lock()
defer hs.mu.Unlock()
if !hs.running() {
if !hs.started {
return
}
hs.started = false
close(hs.stopChan)
}