poll calls cond every interval until it returns a value and true, or the context is canceled. If cond returns a non-nil error, polling stops immediately.
(ctx context.Context, interval time.Duration, cond func(ctx context.Context) (T, bool, error))
| 585 | // or the context is canceled. If cond returns a non-nil error, |
| 586 | // polling stops immediately. |
| 587 | func poll[T any](ctx context.Context, interval time.Duration, cond func(ctx context.Context) (T, bool, error)) (T, error) { |
| 588 | ticker := time.NewTicker(interval) |
| 589 | defer ticker.Stop() |
| 590 | for { |
| 591 | select { |
| 592 | case <-ctx.Done(): |
| 593 | var zero T |
| 594 | return zero, ctx.Err() |
| 595 | case <-ticker.C: |
| 596 | v, done, err := cond(ctx) |
| 597 | if err != nil { |
| 598 | return v, err |
| 599 | } |
| 600 | if done { |
| 601 | return v, nil |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | func develop(ctx context.Context, logger slog.Logger, cfg *devConfig) error { |
| 608 | sigCtx, stop := signal.NotifyContext(ctx, cli.StopSignals...) |