This commit is contained in:
Alex Yatskov 2015-12-17 16:32:21 +09:00
parent 4b5f9abd80
commit 067b501d49

View File

@ -183,12 +183,7 @@ func (gs *goldsmith) newStage() *stage {
func (gs *goldsmith) chain(s *stage, p Plugin) { func (gs *goldsmith) chain(s *stage, p Plugin) {
defer close(s.output) defer close(s.output)
if init, ok := p.(Initializer); ok { init, _ := p.(Initializer)
if s.err = init.Initialize(s); s.err != nil {
return
}
}
accept, _ := p.(Accepter) accept, _ := p.(Accepter)
proc, _ := p.(Processor) proc, _ := p.(Processor)
fin, _ := p.(Finalizer) fin, _ := p.(Finalizer)
@ -196,7 +191,7 @@ func (gs *goldsmith) chain(s *stage, p Plugin) {
var ( var (
wg sync.WaitGroup wg sync.WaitGroup
mtx sync.Mutex mtx sync.Mutex
files []*File batch []*File
) )
dispatch := func(f *File) { dispatch := func(f *File) {
@ -204,11 +199,17 @@ func (gs *goldsmith) chain(s *stage, p Plugin) {
s.output <- f s.output <- f
} else { } else {
mtx.Lock() mtx.Lock()
files = append(files, f) batch = append(batch, f)
mtx.Unlock() mtx.Unlock()
} }
} }
if init != nil {
if s.err = init.Initialize(s); s.err != nil {
return
}
}
for file := range s.input { for file := range s.input {
if file.Err != nil || proc == nil || (accept != nil && !accept.Accept(file)) { if file.Err != nil || proc == nil || (accept != nil && !accept.Accept(file)) {
dispatch(file) dispatch(file)
@ -228,8 +229,8 @@ func (gs *goldsmith) chain(s *stage, p Plugin) {
wg.Wait() wg.Wait()
if fin != nil { if fin != nil {
if s.err = fin.Finalize(s, files); s.err == nil { if s.err = fin.Finalize(s, batch); s.err == nil {
for _, file := range files { for _, file := range batch {
s.output <- file s.output <- file
} }
} }