From 067b501d490e4562f3cac93374099471cce9ce55 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 17 Dec 2015 16:32:21 +0900 Subject: [PATCH] Cleanup --- goldsmith.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/goldsmith.go b/goldsmith.go index f588172..4af6bca 100644 --- a/goldsmith.go +++ b/goldsmith.go @@ -183,12 +183,7 @@ func (gs *goldsmith) newStage() *stage { func (gs *goldsmith) chain(s *stage, p Plugin) { defer close(s.output) - if init, ok := p.(Initializer); ok { - if s.err = init.Initialize(s); s.err != nil { - return - } - } - + init, _ := p.(Initializer) accept, _ := p.(Accepter) proc, _ := p.(Processor) fin, _ := p.(Finalizer) @@ -196,7 +191,7 @@ func (gs *goldsmith) chain(s *stage, p Plugin) { var ( wg sync.WaitGroup mtx sync.Mutex - files []*File + batch []*File ) dispatch := func(f *File) { @@ -204,11 +199,17 @@ func (gs *goldsmith) chain(s *stage, p Plugin) { s.output <- f } else { mtx.Lock() - files = append(files, f) + batch = append(batch, f) mtx.Unlock() } } + if init != nil { + if s.err = init.Initialize(s); s.err != nil { + return + } + } + for file := range s.input { if file.Err != nil || proc == nil || (accept != nil && !accept.Accept(file)) { dispatch(file) @@ -228,8 +229,8 @@ func (gs *goldsmith) chain(s *stage, p Plugin) { wg.Wait() if fin != nil { - if s.err = fin.Finalize(s, files); s.err == nil { - for _, file := range files { + if s.err = fin.Finalize(s, batch); s.err == nil { + for _, file := range batch { s.output <- file } }