2
0

Add listen / notify implemented with pgconn

fixes #553
This commit is contained in:
Jack Christensen
2019-08-24 10:49:10 -05:00
parent b7b52ff079
commit e9770d6ff9
3 changed files with 188 additions and 17 deletions
+13 -11
View File
@@ -55,17 +55,19 @@ func listen() {
}
defer conn.Release()
// TODO - determine how listen should be handled in pgx vs. pgconn
_, err = conn.Exec(context.Background(), "listen chat")
if err != nil {
fmt.Fprintln(os.Stderr, "Error listening to chat channel:", err)
os.Exit(1)
}
conn.Exec(context.Background(), "listen chat")
for {
notification, err := conn.Conn().WaitForNotification(context.Background())
if err != nil {
fmt.Fprintln(os.Stderr, "Error waiting for notification:", err)
os.Exit(1)
}
// for {
// notification, err := conn.WaitForNotification(context.Background())
// if err != nil {
// fmt.Fprintln(os.Stderr, "Error waiting for notification:", err)
// os.Exit(1)
// }
// fmt.Println("PID:", notification.PID, "Channel:", notification.Channel, "Payload:", notification.Payload)
// }
fmt.Println("PID:", notification.PID, "Channel:", notification.Channel, "Payload:", notification.Payload)
}
}