Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
fixed race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Sep 24, 2016
1 parent 68fcda7 commit b3bb41a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions antibody.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"strings"
"sync"

"github.com/caarlos0/gohome"
"github.com/getantibody/antibody/bundle"
Expand All @@ -28,6 +29,7 @@ func New(home string, r io.Reader) *Antibody {
// Bundle processes all given lines and returns the shell content to execute
func (a *Antibody) Bundle() (result string, err error) {
var g errgroup.Group
var lock sync.Mutex
var shs []string
scanner := bufio.NewScanner(a.r)
for scanner.Scan() {
Expand All @@ -36,6 +38,8 @@ func (a *Antibody) Bundle() (result string, err error) {
l = strings.TrimSpace(l)
if l != "" && l[0] != '#' {
s, err := bundle.New(a.Home, l).Get()
lock.Lock()
defer lock.Unlock()
shs = append(shs, s)
return err
}
Expand All @@ -45,9 +49,7 @@ func (a *Antibody) Bundle() (result string, err error) {
if err := scanner.Err(); err != nil {
return result, err
}
if err := g.Wait(); err != nil {
return result, err
}
err = g.Wait()
return strings.Join(shs, "\n"), err
}

Expand Down

0 comments on commit b3bb41a

Please sign in to comment.