Commit d0b36326 authored by Boris Mühmer's avatar Boris Mühmer
Browse files

added usage of buffered channel

parent 8ecb4f62
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ import (
	"log"
	"path"
	"regexp"
	"runtime"
	"sync"

	"repositories.muehmer.net/boris.muehmer/sotatool/offline"
)
@@ -32,12 +34,24 @@ func example01() {
	}

	// work on the file list
	numWorkers := runtime.NumCPU()
	filenames := make(chan string, numWorkers)
	var wg sync.WaitGroup
	for _, file := range files {
		if file.IsDir() {
			continue
		}
		if re.MatchString(file.Name()) {
			savegame.DumpJSONContents(path.Join(sourcedir, file.Name()), destdir)
		if re.MatchString(file.Name()) == false {
			continue
		}
		wg.Add(1)
		filenames <- file.Name()

		go func() {
			defer wg.Done()
			filename := <-filenames
			savegame.DumpJSONContents(path.Join(sourcedir, filename), destdir)
		}()
	}
	wg.Wait()
}