@@ -17,7 +17,7 @@ package oversight
17
17
import (
18
18
"context"
19
19
"errors"
20
- "io/ioutil "
20
+ "io"
21
21
"log"
22
22
"sync"
23
23
"time"
@@ -114,7 +114,7 @@ func (t *Tree) init() {
114
114
DefaultRestartStrategy ()(t )
115
115
}
116
116
if t .logger == nil {
117
- t .logger = log .New (ioutil .Discard , "" , 0 )
117
+ t .logger = log .New (io .Discard , "" , 0 )
118
118
}
119
119
t .children = make (map [string ]childProcess )
120
120
t .stopped = make (chan struct {})
@@ -264,25 +264,23 @@ func (t *Tree) Start(rootCtx context.Context) error {
264
264
defer cancel ()
265
265
t .gracefulCancel = cancel
266
266
for {
267
- select {
268
- case <- ctx .Done ():
269
- return t .drain (ctx )
270
- default :
271
- t .startChildProcesses (ctx , cancel )
272
- t .handleTreeChanges (ctx , cancel )
267
+ if ctx .Err () != nil {
268
+ return t .drain ()
273
269
}
270
+ t .startChildProcesses (ctx , cancel )
271
+ t .handleTreeChanges (ctx , cancel )
274
272
}
275
273
}
276
274
277
- func (t * Tree ) drain (ctx context. Context ) error {
275
+ func (t * Tree ) drain () error {
278
276
select {
279
277
case <- t .stopped :
280
278
return ErrTreeNotRunning
281
279
default :
282
280
}
283
281
close (t .stopped )
284
282
defer t .logger .Printf ("clean up complete" )
285
- t .logger .Printf ("context canceled (before start): %v" , ctx . Err () )
283
+ t .logger .Printf ("draining" )
286
284
t .semaphore .Lock ()
287
285
for i := len (t .childrenOrder ) - 1 ; i >= 0 ; i -- {
288
286
procName := t .childrenOrder [i ]
0 commit comments