This commit is contained in:
Alex Yatskov 2015-12-17 14:12:01 +09:00
parent fc04c86d86
commit 4b36ade9bb
2 changed files with 16 additions and 9 deletions

View File

@ -189,23 +189,26 @@ func (gs *goldsmith) chain(s *stage, p Plugin) {
} }
} }
if proc, ok := p.(Processor); ok { accept, _ := p.(Accepter)
var wg sync.WaitGroup proc, _ := p.(Processor)
for file := range s.input {
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) { go func(f *File) {
defer wg.Done() defer wg.Done()
if proc.Process(s, f) { if proc.Process(s, f) {
s.output <- f s.output <- f
} else {
gs.decFiles()
} }
}(file) }(file)
} }
wg.Wait()
} else {
for file := range s.input {
s.output <- file
}
} }
wg.Wait()
if fin, ok := p.(Finalizer); ok { if fin, ok := p.(Finalizer); ok {
s.err = fin.Finalize(s) s.err = fin.Finalize(s)

View File

@ -59,6 +59,10 @@ type Context interface {
type Plugin interface{} type Plugin interface{}
type Accepter interface {
Accept(file *File) bool
}
type Initializer interface { type Initializer interface {
Initialize(ctx Context) error Initialize(ctx Context) error
} }