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 {
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)

View File

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