StopAndAwaitTerminated asks service to stop, and then waits until service reaches Terminated or Failed state. If service ends in Terminated state, this function returns error. On Failed state, it returns the failure case. Other errors are possible too (eg. if context stops before service does).
(ctx context.Context, service Service)
| 118 | // or Failed state. If service ends in Terminated state, this function returns error. On Failed state, |
| 119 | // it returns the failure case. Other errors are possible too (eg. if context stops before service does). |
| 120 | func StopAndAwaitTerminated(ctx context.Context, service Service) error { |
| 121 | service.StopAsync() |
| 122 | err := service.AwaitTerminated(ctx) |
| 123 | if err == nil { |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | if e := service.FailureCase(); e != nil { |
| 128 | return e |
| 129 | } |
| 130 | |
| 131 | // can happen e.g. if context was canceled |
| 132 | return err |
| 133 | } |
| 134 | |
| 135 | // DescribeService returns name of the service, if it has one, or returns string representation of the service. |
| 136 | func DescribeService(service Service) string { |