MCPcopy Index your code
hub / github.com/coder/coder / poll

Function poll

scripts/develop/main.go:587–605  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

585// or the context is canceled. If cond returns a non-nil error,
586// polling stops immediately.
587func 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
607func develop(ctx context.Context, logger slog.Logger, cfg *devConfig) error {
608 sigCtx, stop := signal.NotifyContext(ctx, cli.StopSignals...)

Callers 3

TestPollFunction · 0.85
waitForHealthyFunction · 0.85
waitForVersionFunction · 0.85

Calls 3

ErrMethod · 0.80
StopMethod · 0.65
DoneMethod · 0.45

Tested by 1

TestPollFunction · 0.68