Skip to content

Instantly share code, notes, and snippets.

@jhenstridge
Last active June 21, 2019 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhenstridge/a46236d699c1005cef5b829abfe069f6 to your computer and use it in GitHub Desktop.
Save jhenstridge/a46236d699c1005cef5b829abfe069f6 to your computer and use it in GitHub Desktop.
Demonstrate godbus RemoveSignal panic
package main
import (
"fmt"
"log"
"time"
"github.com/godbus/dbus"
)
func main() {
bus, err := dbus.SessionBus()
if err != nil {
log.Fatal(err)
}
// Watch for signals
fmt.Println("Setting up signal watch")
ch := make(chan *dbus.Signal)
bus.Signal(ch)
if err := bus.BusObject().AddMatchSignal("com.example.Test", "Signal").Store(); err != nil {
log.Fatal(err)
}
// Send a matching signal, then wait to make sure it has been delivered
fmt.Println("Sending signal")
if err := bus.Emit("/", "com.example.Test.Signal"); err != nil {
log.Fatal(err)
}
time.Sleep(5 * time.Second)
// Remove the signal watch, and give a little time to settle
fmt.Println("Removing signal watch")
bus.RemoveSignal(ch)
close(ch)
time.Sleep(5 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment