Skip to content

Commit

Permalink
Update src/content/doc-sdk-golang/methods/live_notification.mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekwuno authored Feb 26, 2025
1 parent 3269f4b commit 1499ebb
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/content/doc-sdk-golang/methods/live_notification.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,38 @@ db.LiveNotifications[UUID string](queryUuid)
```go title="Example"
package main

package main

import (
"fmt"
"github.com/surrealdb/surrealdb.go"
"github.com/surrealdb/surrealdb.go/pkg/connection"
"fmt"
"os"
"os/signal"
"syscall"
)

// Assume db is your database connection with a LiveNotifications method.
func main() {
// Assuming db is an instance of your database connection
// and queryUuid is from a previous Live() call
queryUuid := "your-query-uuid-here"
// Assuming queryUuid is obtained from a previous Live() call.
queryUuid := "your-query-uuid-here"

notifications, err := db.LiveNotifications(queryUuid)
if err != nil {
fmt.Println("Error setting up notifications:", err)
return
}

// Listen for notifications in a goroutine.
go func() {
for notification := range notifications {
// Process each notification as it arrives.
fmt.Printf("Received notification: %+v\n", notification)
}
}()

notifications, err := db.LiveNotifications(queryUuid)
if err != nil {
fmt.Println("Error setting up notifications:", err)
return
}
// Wait for a ctrl-C (SIGINT) or termination signal (SIGTERM) before exiting.
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs

// Listen for notifications in a goroutine
go func() {
for notification := range notifications {
// Process each notification as it arrives
fmt.Printf("Received notification: %+v\n", notification)
}
}()
}
fmt.Println("Exiting...")
}

0 comments on commit 1499ebb

Please sign in to comment.