refactor(channels): replace bool with atomic.Bool for running state in BaseChannel
This commit is contained in:
parent
420eadc2ba
commit
b1cbaaba57
1 changed files with 4 additions and 4 deletions
|
|
@ -3,6 +3,7 @@ package channels
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/sipeed/picoclaw/pkg/bus"
|
"github.com/sipeed/picoclaw/pkg/bus"
|
||||||
)
|
)
|
||||||
|
|
@ -19,7 +20,7 @@ type Channel interface {
|
||||||
type BaseChannel struct {
|
type BaseChannel struct {
|
||||||
config any
|
config any
|
||||||
bus *bus.MessageBus
|
bus *bus.MessageBus
|
||||||
running bool
|
running atomic.Bool
|
||||||
name string
|
name string
|
||||||
allowList []string
|
allowList []string
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +31,6 @@ func NewBaseChannel(name string, config any, bus *bus.MessageBus, allowList []st
|
||||||
bus: bus,
|
bus: bus,
|
||||||
name: name,
|
name: name,
|
||||||
allowList: allowList,
|
allowList: allowList,
|
||||||
running: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ func (c *BaseChannel) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BaseChannel) IsRunning() bool {
|
func (c *BaseChannel) IsRunning() bool {
|
||||||
return c.running
|
return c.running.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BaseChannel) IsAllowed(senderID string) bool {
|
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) {
|
func (c *BaseChannel) SetRunning(running bool) {
|
||||||
c.running = running
|
c.running.Store(running)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue