helpers.go 357 B

12345678910111213
  1. package agent
  2. import "golang.org/x/net/context"
  3. // runctx blocks until the function exits, closed is closed, or the context is
  4. // cancelled. Call as part of go statement.
  5. func runctx(ctx context.Context, closed chan struct{}, errs chan error, fn func(ctx context.Context) error) {
  6. select {
  7. case errs <- fn(ctx):
  8. case <-closed:
  9. case <-ctx.Done():
  10. }
  11. }