remove export publisher, pooler

This commit is contained in:
onyx-and-iris 2022-06-26 01:41:05 +01:00
parent 83dccb483b
commit 717c738583
2 changed files with 14 additions and 14 deletions

View File

@ -6,17 +6,17 @@ type observer interface {
} }
// Publisher defines methods that support observers // Publisher defines methods that support observers
type Publisher struct { type publisher struct {
observerList []observer observerList []observer
} }
// Register adds an observer to observerList // Register adds an observer to observerList
func (p *Publisher) Register(o observer) { func (p *publisher) Register(o observer) {
p.observerList = append(p.observerList, o) p.observerList = append(p.observerList, o)
} }
// Deregister removes an observer from observerList // Deregister removes an observer from observerList
func (p *Publisher) Deregister(o observer) { func (p *publisher) Deregister(o observer) {
var indexToRemove int var indexToRemove int
for i, observer := range p.observerList { for i, observer := range p.observerList {
@ -30,7 +30,7 @@ func (p *Publisher) Deregister(o observer) {
} }
// notify updates observers of any changes // notify updates observers of any changes
func (p *Publisher) notify(subject string) { func (p *publisher) notify(subject string) {
for _, observer := range p.observerList { for _, observer := range p.observerList {
observer.OnUpdate(subject) observer.OnUpdate(subject)
} }
@ -38,20 +38,20 @@ func (p *Publisher) notify(subject string) {
// Pooler continuously polls the dirty paramters // Pooler continuously polls the dirty paramters
// it is expected to be run in a goroutine // it is expected to be run in a goroutine
type Pooler struct { type pooler struct {
run bool run bool
Publisher publisher
} }
func newPooler() *Pooler { func newPooler() *pooler {
p := &Pooler{ p := &pooler{
run: true, run: true,
} }
go p.runner() go p.runner()
return p return p
} }
func (p *Pooler) runner() { func (p *pooler) runner() {
for p.run { for p.run {
if pdirty() { if pdirty() {
p.notify("pdirty") p.notify("pdirty")

View File

@ -15,7 +15,7 @@ type remote struct {
Command *command Command *command
Vban *vban Vban *vban
Pooler *Pooler pooler *pooler
} }
// String implements the fmt.stringer interface // String implements the fmt.stringer interface
@ -26,14 +26,14 @@ func (r *remote) String() string {
// Login logs into the API // Login logs into the API
// then it intializes the pooler // then it intializes the pooler
func (r *remote) Login() { func (r *remote) Login() {
r.Pooler = newPooler() r.pooler = newPooler()
login(r.kind.name) login(r.kind.name)
} }
// Logout logs out of the API // Logout logs out of the API
// it also terminates the pooler // it also terminates the pooler
func (r *remote) Logout() { func (r *remote) Logout() {
r.Pooler.run = false r.pooler.run = false
logout() logout()
} }
@ -51,12 +51,12 @@ func (r *remote) SendText(script string) {
// Register forwards the register method to Pooler // Register forwards the register method to Pooler
func (r *remote) Register(o observer) { func (r *remote) Register(o observer) {
r.Pooler.Register(o) r.pooler.Register(o)
} }
// Register forwards the deregister method to Pooler // Register forwards the deregister method to Pooler
func (r *remote) Deregister(o observer) { func (r *remote) Deregister(o observer) {
r.Pooler.Deregister(o) r.pooler.Deregister(o)
} }
type remoteBuilder interface { type remoteBuilder interface {