func Run(ctx context.Context, processes []Process, signals []os.Signal) (os.Signal, []error, error)
Run starts each process, waits for any signal in `notify` or until ctx is cancelled, then cancels each process. It blocks until all processes have been stopped with Stop() and all process Start() functions mark themselves as completely done().
The first return value is the os.Signal received.
The second return value is a list of errors for processes that returned errors when being cancelled.
The third return value returns any startup error.
The second return value may be non-empty even when the third return value is non-nil when there is both a startup error and an error stopping any previously started processes e.g. if process one starts but process two fails, then process one needs to be cancelled but may also run into an error cancelling.
Process defines a long-lived cancellable process
type Process interface { // Start launches a process. This shouldn't block, so launch goroutines or // other programs as necessary. Call done() when that goroutine returns // or that process has terminated. If Start returns an error, then done() // must not be called. Start(done func()) error // Stop stops a process. Derive from the context as necessary e.g. // use context.WithTimeout Stop(context.Context) error }
Name | Synopsis |
---|---|
examples | |
multiportserver | Start HTTP servers on multiple ports with graceful shutdown |