Skip to content

Commit

Permalink
Use a struct instead of int64 for atomic
Browse files Browse the repository at this point in the history
Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

`go vet` complains about direct assignment to an atomic value. Hence, an
anonymous struct to fix the problem.
  • Loading branch information
dharmit committed Jul 21, 2022
1 parent d4c9206 commit f1fedd2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/odo/cli/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func (o *LogsOptions) Run(_ context.Context) error {
}

uniqueContainerNames := map[string]struct{}{}
var goroutines int64 // keep a track of running goroutines so that we don't exit prematurely
errChan := make(chan error) // errors are put on this channel
var goroutines struct{ count int64 } // keep a track of running goroutines so that we don't exit prematurely
errChan := make(chan error) // errors are put on this channel
var mu sync.Mutex

for {
Expand All @@ -146,10 +146,10 @@ func (o *LogsOptions) Run(_ context.Context) error {
logs := containerLogs.Logs

if o.follow {
goroutines = atomic.AddInt64(&goroutines, 1)
atomic.AddInt64(&goroutines.count, 1)
go func(out io.Writer) {
defer func() {
goroutines = atomic.AddInt64(&goroutines, -1)
atomic.AddInt64(&goroutines.count, -1)
}()
err = printLogs(uniqueName, logs, out, colour, &mu)
if err != nil {
Expand All @@ -168,7 +168,7 @@ func (o *LogsOptions) Run(_ context.Context) error {
case err = <-events.Err:
return err
case <-events.Done:
if goroutines == 0 {
if goroutines.count == 0 {
if len(uniqueContainerNames) == 0 {
// This will be the case when:
// 1. user specifies --dev flag, but the component's running in Deploy mode
Expand Down

0 comments on commit f1fedd2

Please sign in to comment.