Last active
June 21, 2019 09:30
-
-
Save jhenstridge/a46236d699c1005cef5b829abfe069f6 to your computer and use it in GitHub Desktop.
Demonstrate godbus RemoveSignal panic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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