This commit is contained in:
Alex Yatskov 2015-11-10 23:05:07 +09:00
parent b9ffe6bc66
commit 1c8f6109f9

View File

@ -151,26 +151,17 @@ func (gs *goldsmith) chain(s stage, c Chainer) {
input = make(chan *File) input = make(chan *File)
) )
defer func() {
wg.Wait()
close(s.output)
}()
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done()
for file := range output { for file := range output {
s.output <- file s.output <- file
} }
wg.Done()
}() }()
wg.Add(1) wg.Add(1)
go func() { go func() {
defer func() {
close(input)
wg.Done()
}()
f, _ := c.(Filterer) f, _ := c.(Filterer)
for file := range s.input { for file := range s.input {
if file.flags&FileFlagStatic != 0 || (f != nil && f.Filter(file.Path)) { if file.flags&FileFlagStatic != 0 || (f != nil && f.Filter(file.Path)) {
@ -179,9 +170,17 @@ func (gs *goldsmith) chain(s stage, c Chainer) {
input <- file input <- file
} }
} }
close(input)
wg.Done()
}() }()
go c.Chain(gs, input, output) go func() {
c.Chain(gs, input, output)
wg.Wait()
close(s.output)
}()
} }
func (gs *goldsmith) NewFile(path string) *File { func (gs *goldsmith) NewFile(path string) *File {
@ -240,7 +239,7 @@ func (gs *goldsmith) Chain(c Chainer, err error) Goldsmith {
} }
if gs.err = err; gs.err == nil { if gs.err = err; gs.err == nil {
go gs.chain(gs.makeStage(), c) gs.chain(gs.makeStage(), c)
} }
return gs return gs