From 632cd9049f630101bfd1ba8e83efa6ec2b697fd0 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 9 Dec 2022 00:55:18 +0000 Subject: [PATCH] run o.Listen() in goroutine. run main thread for 30 seconds --- examples/observer/main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/observer/main.go b/examples/observer/main.go index 6bb07fb..a1f7c85 100644 --- a/examples/observer/main.go +++ b/examples/observer/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "time" log "github.com/sirupsen/logrus" @@ -16,8 +17,7 @@ type observer struct { // newObserver returns an observer type func newObserver(vm *voicemeeter.Remote) *observer { - o := &observer{vm, make(chan string)} - return o + return &observer{vm, make(chan string)} } // OnUpdate satisfies the observer interface defined in publisher.go @@ -49,7 +49,7 @@ func init() { func runObserver(vm *voicemeeter.Remote) { o := newObserver(vm) - o.Listen() + go o.Listen() } // main connects to Voiceemeter, registers observer for updates @@ -62,6 +62,8 @@ func main() { defer vm.Logout() runObserver(vm) + + time.Sleep(time.Duration(30) * time.Second) } // vmConnect connects to Voicemeeter potato and logs into the API