refactor(channels): replace bool with atomic.Bool for running state in BaseChannel

This commit is contained in:
Hoshina
2026-02-21 00:00:29 +08:00
parent 420eadc2ba
commit b1cbaaba57
+4 -4
View File
@@ -3,6 +3,7 @@ package channels
import (
"context"
"strings"
"sync/atomic"
"github.com/sipeed/picoclaw/pkg/bus"
)
@@ -19,7 +20,7 @@ type Channel interface {
type BaseChannel struct {
config any
bus *bus.MessageBus
running bool
running atomic.Bool
name string
allowList []string
}
@@ -30,7 +31,6 @@ func NewBaseChannel(name string, config any, bus *bus.MessageBus, allowList []st
bus: bus,
name: name,
allowList: allowList,
running: false,
}
}
@@ -39,7 +39,7 @@ func (c *BaseChannel) Name() string {
}
func (c *BaseChannel) IsRunning() bool {
return c.running
return c.running.Load()
}
func (c *BaseChannel) IsAllowed(senderID string) bool {
@@ -99,5 +99,5 @@ func (c *BaseChannel) HandleMessage(senderID, chatID, content string, media []st
}
func (c *BaseChannel) SetRunning(running bool) {
c.running = running
c.running.Store(running)
}