Skip to content

Commit 77285fa

Browse files
cypharlifubang
authored andcommitted
go fix: use (*sync.WaitGroup).Go
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
1 parent 8a58fb4 commit 77285fa

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

events.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,14 @@ information is displayed once every 5 seconds.`,
5353
events = make(chan *types.Event, 1024)
5454
group = &sync.WaitGroup{}
5555
)
56-
group.Add(1)
57-
go func() {
58-
defer group.Done()
56+
group.Go(func() {
5957
enc := json.NewEncoder(os.Stdout)
6058
for e := range events {
6159
if err := enc.Encode(e); err != nil {
6260
logrus.Error(err)
6361
}
6462
}
65-
}()
63+
})
6664
if context.Bool("stats") {
6765
s, err := container.Stats()
6866
if err != nil {

tests/cmd/recvtty/recvtty.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,13 @@ func handleSingle(path string, noStdin bool) error {
117117
wg sync.WaitGroup
118118
inErr, outErr error
119119
)
120-
wg.Add(1)
121-
go func() {
120+
wg.Go(func() {
122121
_, outErr = io.Copy(os.Stdout, c)
123-
wg.Done()
124-
}()
122+
})
125123
if !noStdin {
126-
wg.Add(1)
127-
go func() {
124+
wg.Go(func() {
128125
_, inErr = io.Copy(c, os.Stdin)
129-
wg.Done()
130-
}()
126+
})
131127
}
132128

133129
// Only close the master fd once we've stopped copying.

0 commit comments

Comments
 (0)