mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
refactor(channels): replace bool with atomic.Bool for running state in BaseChannel
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user