From 25f39fcb6aa03abb83f73f0e17f61b9fb1303031 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Sat, 25 Jun 2022 20:36:34 +0100 Subject: [PATCH] expand example to demonstrate deregister --- examples/observer/observer.go | 22 +++++++++++++++++----- voicemeeter/publisher.go | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/examples/observer/observer.go b/examples/observer/observer.go index fec0d38..737e124 100644 --- a/examples/observer/observer.go +++ b/examples/observer/observer.go @@ -7,20 +7,32 @@ import ( "github.com/onyx-and-iris/voicemeeter-api-go/voicemeeter" ) -type observer struct{} +type observer struct { + i int +} func (o observer) OnUpdate(subject string) { - fmt.Println(subject) + fmt.Println(o.i, subject) } func main() { vmRem := voicemeeter.GetRemote("banana") vmRem.Login() - o := observer{} - vmRem.Pooler.Publisher.Register(o) + o := observer{1} + 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() } diff --git a/voicemeeter/publisher.go b/voicemeeter/publisher.go index 015714b..e4dce88 100644 --- a/voicemeeter/publisher.go +++ b/voicemeeter/publisher.go @@ -47,10 +47,10 @@ func newPooler() *Pooler { func (r *Pooler) runner() { for r.run { if pdirty() { - r.Publisher.notify("pdirty") + r.notify("pdirty") } if mdirty() { - r.Publisher.notify("mdirty") + r.notify("mdirty") } } }