Skip to content

Commit 74db0a6

Browse files
committed
oversight: upgrade minimum Go version
1 parent 8b82b43 commit 74db0a6

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

easy/easy_example_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package easy_test
1717
import (
1818
"context"
1919
"fmt"
20-
"io/ioutil"
20+
"io"
2121
"log"
2222
"sync"
2323
"time"
@@ -29,7 +29,7 @@ func Example() {
2929
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
3030
defer cancel()
3131
var wg sync.WaitGroup
32-
ctx = oversight.WithContext(ctx, oversight.WithLogger(log.New(ioutil.Discard, "", 0)))
32+
ctx = oversight.WithContext(ctx, oversight.WithLogger(log.New(io.Discard, "", 0)))
3333
wg.Add(1)
3434
serviceName, err := oversight.Add(ctx, func(ctx context.Context) error {
3535
select {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module cirello.io/oversight
22

3-
go 1.12
3+
go 1.22

tree.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package oversight
1717
import (
1818
"context"
1919
"errors"
20-
"io/ioutil"
20+
"io"
2121
"log"
2222
"sync"
2323
"time"
@@ -114,7 +114,7 @@ func (t *Tree) init() {
114114
DefaultRestartStrategy()(t)
115115
}
116116
if t.logger == nil {
117-
t.logger = log.New(ioutil.Discard, "", 0)
117+
t.logger = log.New(io.Discard, "", 0)
118118
}
119119
t.children = make(map[string]childProcess)
120120
t.stopped = make(chan struct{})
@@ -264,25 +264,23 @@ func (t *Tree) Start(rootCtx context.Context) error {
264264
defer cancel()
265265
t.gracefulCancel = cancel
266266
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()
273269
}
270+
t.startChildProcesses(ctx, cancel)
271+
t.handleTreeChanges(ctx, cancel)
274272
}
275273
}
276274

277-
func (t *Tree) drain(ctx context.Context) error {
275+
func (t *Tree) drain() error {
278276
select {
279277
case <-t.stopped:
280278
return ErrTreeNotRunning
281279
default:
282280
}
283281
close(t.stopped)
284282
defer t.logger.Printf("clean up complete")
285-
t.logger.Printf("context canceled (before start): %v", ctx.Err())
283+
t.logger.Printf("draining")
286284
t.semaphore.Lock()
287285
for i := len(t.childrenOrder) - 1; i >= 0; i-- {
288286
procName := t.childrenOrder[i]

0 commit comments

Comments
 (0)