expand example to demonstrate deregister

This commit is contained in:
onyx-and-iris 2022-06-25 20:36:34 +01:00
parent d7be997fae
commit 25f39fcb6a
2 changed files with 19 additions and 7 deletions

View File

@ -7,20 +7,32 @@ import (
"github.com/onyx-and-iris/voicemeeter-api-go/voicemeeter" "github.com/onyx-and-iris/voicemeeter-api-go/voicemeeter"
) )
type observer struct{} type observer struct {
i int
}
func (o observer) OnUpdate(subject string) { func (o observer) OnUpdate(subject string) {
fmt.Println(subject) fmt.Println(o.i, subject)
} }
func main() { func main() {
vmRem := voicemeeter.GetRemote("banana") vmRem := voicemeeter.GetRemote("banana")
vmRem.Login() vmRem.Login()
o := observer{} o := observer{1}
vmRem.Pooler.Publisher.Register(o) o2 := observer{2}
o3 := observer{3}
o4 := observer{4}
vmRem.Pooler.Register(o)
vmRem.Pooler.Register(o2)
vmRem.Pooler.Register(o3)
vmRem.Pooler.Register(o4)
time.Sleep(10 * time.Second) time.Sleep(5 * time.Second)
vmRem.Pooler.Deregister(o2)
time.Sleep(5 * time.Second)
vmRem.Logout() vmRem.Logout()
} }

View File

@ -47,10 +47,10 @@ func newPooler() *Pooler {
func (r *Pooler) runner() { func (r *Pooler) runner() {
for r.run { for r.run {
if pdirty() { if pdirty() {
r.Publisher.notify("pdirty") r.notify("pdirty")
} }
if mdirty() { if mdirty() {
r.Publisher.notify("mdirty") r.notify("mdirty")
} }
} }
} }