Skip to content

Commit

Permalink
oversight: upgrade minimum Go version
Browse files Browse the repository at this point in the history
  • Loading branch information
ucirello committed Jul 7, 2024
1 parent 8b82b43 commit 74db0a6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions easy/easy_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package easy_test
import (
"context"
"fmt"
"io/ioutil"
"io"
"log"
"sync"
"time"
Expand All @@ -29,7 +29,7 @@ func Example() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
var wg sync.WaitGroup
ctx = oversight.WithContext(ctx, oversight.WithLogger(log.New(ioutil.Discard, "", 0)))
ctx = oversight.WithContext(ctx, oversight.WithLogger(log.New(io.Discard, "", 0)))
wg.Add(1)
serviceName, err := oversight.Add(ctx, func(ctx context.Context) error {
select {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module cirello.io/oversight

go 1.12
go 1.22
18 changes: 8 additions & 10 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package oversight
import (
"context"
"errors"
"io/ioutil"
"io"
"log"
"sync"
"time"
Expand Down Expand Up @@ -114,7 +114,7 @@ func (t *Tree) init() {
DefaultRestartStrategy()(t)
}
if t.logger == nil {
t.logger = log.New(ioutil.Discard, "", 0)
t.logger = log.New(io.Discard, "", 0)
}
t.children = make(map[string]childProcess)
t.stopped = make(chan struct{})
Expand Down Expand Up @@ -264,25 +264,23 @@ func (t *Tree) Start(rootCtx context.Context) error {
defer cancel()
t.gracefulCancel = cancel
for {
select {
case <-ctx.Done():
return t.drain(ctx)
default:
t.startChildProcesses(ctx, cancel)
t.handleTreeChanges(ctx, cancel)
if ctx.Err() != nil {
return t.drain()
}
t.startChildProcesses(ctx, cancel)
t.handleTreeChanges(ctx, cancel)
}
}

func (t *Tree) drain(ctx context.Context) error {
func (t *Tree) drain() error {
select {
case <-t.stopped:
return ErrTreeNotRunning
default:
}
close(t.stopped)
defer t.logger.Printf("clean up complete")
t.logger.Printf("context canceled (before start): %v", ctx.Err())
t.logger.Printf("draining")
t.semaphore.Lock()
for i := len(t.childrenOrder) - 1; i >= 0; i-- {
procName := t.childrenOrder[i]
Expand Down

0 comments on commit 74db0a6

Please sign in to comment.