diff --git a/Makefile b/Makefile index 27dbccf26..690958de0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort) +EXAMPLE_GO_MOD_DIRS := $(shell find ./example/ -type f -name 'go.mod' -exec dirname {} \; | sort) test: set -e; for dir in $(ALL_GO_MOD_DIRS); do \ @@ -21,3 +22,9 @@ go_mod_tidy: fmt: gofmt -w -s ./ goimports -w -local github.com/uptrace/bun ./ + +run-examples: + set -e; for dir in $(EXAMPLE_GO_MOD_DIRS); do \ + echo "go run . in $${dir}"; \ + (cd "$${dir}" && go run .); \ + done diff --git a/example/pg-listen/main.go b/example/pg-listen/main.go index 1654f8215..30e508dcf 100644 --- a/example/pg-listen/main.go +++ b/example/pg-listen/main.go @@ -21,15 +21,19 @@ func main() { db := bun.NewDB(sqldb, pgdialect.New()) db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true))) + ln := pgdriver.NewListener(db) + go func() { - for tm := range time.Tick(time.Second) { - if err := pgdriver.Notify(ctx, db, "mychan1", tm.Format(time.RFC3339)); err != nil { + for i := 0; i < 3; i++ { + payload := time.Now().Format(time.RFC3339) + if err := pgdriver.Notify(ctx, db, "mychan1", payload); err != nil { panic(err) } + time.Sleep(time.Second) } + _ = ln.Close() }() - ln := pgdriver.NewListener(db) if err := ln.Listen(ctx, "mychan1", "mychan2"); err != nil { panic(err) }