From 4b36ade9bb286892239b15ad0ee2450299473e58 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 17 Dec 2015 14:12:01 +0900 Subject: [PATCH] Bugfixes --- goldsmith.go | 21 ++++++++++++--------- types.go | 4 ++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/goldsmith.go b/goldsmith.go index cbd8456..1bc4666 100644 --- a/goldsmith.go +++ b/goldsmith.go @@ -189,23 +189,26 @@ func (gs *goldsmith) chain(s *stage, p Plugin) { } } - if proc, ok := p.(Processor); ok { - var wg sync.WaitGroup - for file := range s.input { + accept, _ := p.(Accepter) + proc, _ := p.(Processor) + + var wg sync.WaitGroup + for file := range s.input { + if file.Err != nil || proc == nil || (accept != nil && !accept.Accept(file)) { + s.output <- file + } else { + wg.Add(1) go func(f *File) { defer wg.Done() if proc.Process(s, f) { s.output <- f + } else { + gs.decFiles() } }(file) } - - wg.Wait() - } else { - for file := range s.input { - s.output <- file - } } + wg.Wait() if fin, ok := p.(Finalizer); ok { s.err = fin.Finalize(s) diff --git a/types.go b/types.go index 3d7b6a6..38f20d5 100644 --- a/types.go +++ b/types.go @@ -59,6 +59,10 @@ type Context interface { type Plugin interface{} +type Accepter interface { + Accept(file *File) bool +} + type Initializer interface { Initialize(ctx Context) error }