Skip to content

Commit

Permalink
Inline WaitGroup.Spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
max-melentyev committed Apr 23, 2024
1 parent f4cc81e commit 2e917d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
27 changes: 18 additions & 9 deletions pkg/controller/ec2/instance/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package instance

import (
"context"
"sync"
"sync/atomic"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -180,15 +181,17 @@ func (e *external) describeInstance(ctx context.Context, instanceId string) (
awsec2.DescribeInstanceAttributeOutput,
error,
) {
wg := WaitGroup{}
wg := sync.WaitGroup{}

var describeOutput *awsec2.DescribeInstancesOutput
var describeError error
wg.Spawn(func() {
wg.Add(1)
go func() {
describeOutput, describeError = e.client.DescribeInstances(ctx, &awsec2.DescribeInstancesInput{
InstanceIds: []string{instanceId},
})
})
wg.Done()
}()

attrs := awsec2.DescribeInstanceAttributeOutput{}
attrsErr := atomic.Pointer[error]{}
Expand All @@ -199,29 +202,35 @@ func (e *external) describeInstance(ctx context.Context, instanceId string) (
})
}

wg.Spawn(func() {
wg.Add(1)
go func() {
if r, err := descAttr(types.InstanceAttributeNameDisableApiTermination); err != nil {
attrsErr.Store(&err)
} else {
attrs.DisableApiTermination = r.DisableApiTermination
}
})
wg.Done()
}()

wg.Spawn(func() {
wg.Add(1)
go func() {
if r, err := descAttr(types.InstanceAttributeNameInstanceInitiatedShutdownBehavior); err != nil {
attrsErr.Store(&err)
} else {
attrs.InstanceInitiatedShutdownBehavior = r.InstanceInitiatedShutdownBehavior
}
})
wg.Done()
}()

wg.Spawn(func() {
wg.Add(1)
go func() {
if r, err := descAttr(types.InstanceAttributeNameUserData); err != nil {
attrsErr.Store(&err)
} else {
attrs.UserData = r.UserData
}
})
wg.Done()
}()

wg.Wait()

Expand Down
16 changes: 0 additions & 16 deletions pkg/controller/ec2/instance/wait_group.go

This file was deleted.

0 comments on commit 2e917d8

Please sign in to comment.