diff --git a/cmd/pg-pulse/main.go b/cmd/pg-pulse/main.go index 20e260b..fbd0465 100644 --- a/cmd/pg-pulse/main.go +++ b/cmd/pg-pulse/main.go @@ -7,6 +7,7 @@ import ( "fmt" "log" "os" + "sync" "time" "gitea.bel.blue/bel/with" @@ -30,14 +31,20 @@ func run(ctx context.Context) error { } for i := 0; i < *p-1; i++ { - go with.PSQL(ctx, *c, func(pg *sql.DB) error { - with.GoEvery(ctx, *d, func() { - if _, err := pg.ExecContext(ctx, `SELECT 1`); err != nil { - log.Println("!", err) - } + func() { + connected := &sync.WaitGroup{} + connected.Add(1) + go with.PSQL(ctx, *c, func(pg *sql.DB) error { + connected.Done() + with.GoEvery(ctx, *d, func() { + if _, err := pg.ExecContext(ctx, `SELECT 1`); err != nil { + log.Println("!", err) + } + }) + return ctx.Err() }) - return ctx.Err() - }) + connected.Wait() + }() } return with.PSQL(ctx, *c, func(pg *sql.DB) error {