github.com/golazy/golazy@v0.0.7-0.20221012133820-968fe65a0b65/lazydev/runner/README.md (about) 1 # runner 2 3 Package runner run a restart a program on signals 4 5 ## Variables 6 7 ```golang 8 var ( 9 // ErrRunning is the return error in the Start method 10 ErrRunning = errors.New("Program is already running") 11 // ErrCantKill is returned by Restart and Stop in case the process can't be killed 12 ErrCantKill = errors.New("Process is still alive after sending the kill signal") 13 // ErrNotRunning is retuned by the Stop and Signal command when the program is not running 14 ErrNotRunning = errors.New("Process is not running") 15 // ErrRunnerClosed is returned by any method when the runner is closed 16 ErrRunnerClosed = errors.New("Runner is closed") 17 ) 18 ``` 19 20 DefaultRunnerOptions are used when no RunnerOptions are passed 21 22 ```golang 23 var DefaultRunnerOptions = &Options{ 24 KillWaitPeriod: time.Second, 25 ReadyString: []string{"Listening", "Started", "Ready"}, 26 } 27 ``` 28 29 ## Types 30 31 ### type [EventReady](/runner.go#L45) 32 33 `type EventReady struct { ... }` 34 35 EventReady is fired whenever the command outputs the string Listening 36 37 ### type [EventRestart](/runner.go#L50) 38 39 `type EventRestart struct { ... }` 40 41 EventRestart is fired whenever Restart is called 42 43 ### type [EventSignal](/runner.go#L39) 44 45 `type EventSignal struct { ... }` 46 47 EventSignal is fired whenever 48 49 ### type [EventStart](/runner.go#L26) 50 51 `type EventStart struct { ... }` 52 53 EventStart is fired whenever Start is called 54 55 ### type [EventStarted](/runner.go#L64) 56 57 `type EventStarted struct { ... }` 58 59 EventStarted is fired whenever the subprocess is started 60 61 ### type [EventStop](/runner.go#L33) 62 63 `type EventStop struct { ... }` 64 65 EventStop is fired whenever Stop is called 66 67 ### type [EventStopped](/runner.go#L57) 68 69 `type EventStopped struct { ... }` 70 71 EventStopped is fired whenever the process exits 72 73 ### type [Options](/runner.go#L14) 74 75 `type Options struct { ... }` 76 77 Options holds the runner options 78 79 ### type [Runner](/runner.go#L69) 80 81 `type Runner struct { ... }` 82 83 Runner is an command runner that produces events on start/stop and restart 84 85 #### func [New](/runner.go#L145) 86 87 `func New(cmd *exec.Cmd, options *Options) *Runner` 88 89 New creates a new runner for the given command 90 if options is nil, New will use DefaultRunnerOptions 91 92 #### func (*Runner) [Close](/runner.go#L87) 93 94 `func (r *Runner) Close() error` 95 96 Close stop all the internal goroutines 97 After Close is called the runner can't be used anymore 98 99 #### func (*Runner) [Restart](/runner.go#L108) 100 101 `func (r *Runner) Restart() error` 102 103 Restart restart the process by calling Stop and then Restart. If the process is not runing it will be the same as calling Start 104 105 #### func (*Runner) [Signal](/runner.go#L131) 106 107 `func (r *Runner) Signal(s syscall.Signal) error` 108 109 Signal sends a signal to the process. 110 If the process is not running it returns ErrNotRunning 111 112 #### func (*Runner) [Start](/runner.go#L98) 113 114 `func (r *Runner) Start() error` 115 116 Start starts the command 117 If the command is already running it returns ErrRunning 118 119 #### func (*Runner) [Stop](/runner.go#L120) 120 121 `func (r *Runner) Stop() error` 122 123 Stop stops the process. 124 It will send an interrupt signal to the process. 125 If after KillWaitPeriod the process is still alive, it will send a kill signal 126 127 --- 128 Readme created from Go doc with [goreadme](https://github.com/posener/goreadme)