Run is a convenience that Start()s the operator, blocks until ctx is canceled, then performs a synchronous Shutdown with a derived timeout. Use it from main() and tests; library consumers that want fine-grained control should call Start and Shutdown directly.
(ctx context.Context)
| 231 | // it from main() and tests; library consumers that want fine-grained control |
| 232 | // should call Start and Shutdown directly. |
| 233 | func (op *ShellOperator) Run(ctx context.Context) error { |
| 234 | if err := op.Start(ctx); err != nil { |
| 235 | return err |
| 236 | } |
| 237 | <-ctx.Done() |
| 238 | |
| 239 | shutdownCtx, cancel := context.WithTimeout(context.Background(), DefaultShutdownTimeout) |
| 240 | defer cancel() |
| 241 | return op.Shutdown(shutdownCtx) |
| 242 | } |
| 243 | |
| 244 | // Shutdown gracefully tears down everything started by Start. It is |
| 245 | // synchronous: when Shutdown returns, no goroutine spawned by the operator is |
no test coverage detected