Skip to content

Commit

Permalink
chore: add command to run examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Mar 2, 2022
1 parent 9ead80f commit b393db0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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
10 changes: 7 additions & 3 deletions example/pg-listen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b393db0

Please sign in to comment.