Add concurrency limiting semaphore

main
Mari 4 years ago
parent 0dd446c293
commit a719cd25a1
  1. 13
      drive-demuxer.go

@ -16,6 +16,7 @@ type TopLevel struct {
LeftOutput string LeftOutput string
CombinedOutput string CombinedOutput string
RightOutput string RightOutput string
OpenHandles chan int
} }
type Step struct { type Step struct {
@ -181,7 +182,7 @@ func (s *Step) ListChildren() []string {
results[file.Name()] = true results[file.Name()] = true
} }
out := make([]string, 0, len(results)) out := make([]string, 0, len(results))
for file, _ := range results { for file := range results {
out = append(out, file) out = append(out, file)
} }
return out return out
@ -298,7 +299,11 @@ func (s *Step) Walk() {
} }
wg.Add(1) wg.Add(1)
go func() { go func() {
defer func() { wg.Done() }() defer func() {
<-s.OpenHandles
wg.Done()
}()
s.OpenHandles <- 1
substep.Walk() substep.Walk()
s.RemoveInputDirs(child) s.RemoveInputDirs(child)
}() }()
@ -314,7 +319,9 @@ func (s *Step) Walk() {
} }
func main() { func main() {
settings := TopLevel{} settings := TopLevel{
OpenHandles: make(chan int, 300),
}
flag.StringVar(&settings.LeftInput, flag.StringVar(&settings.LeftInput,
"left-input", "./input/left", "The name of the left side of the input.") "left-input", "./input/left", "The name of the left side of the input.")
flag.StringVar(&settings.RightInput, flag.StringVar(&settings.RightInput,

Loading…
Cancel
Save