From 6a3467e034798fa1153170fadb0aab50fac9f640 Mon Sep 17 00:00:00 2001 From: GrailFinder Date: Thu, 16 Feb 2023 14:55:19 +0300 Subject: Enha: try concurrency --- main.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 52db403..b7b84f2 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "path" "path/filepath" "strings" + "time" ) const ( @@ -165,14 +166,9 @@ func main() { // filteredUtterances := []*Utterance{} // === concurrent === - queue := make(chan *Utterance, 1000) + queue := make(chan *Utterance) done := make(chan bool, 1) - workers := 10 - for i := 0; i < workers; i++ { - go worker(queue, i, done) - } - for _, ut := range utterances { if _, err := os.Stat(ut.OutPath); os.IsNotExist(err) { queue <- ut @@ -181,8 +177,23 @@ func main() { // } } } - done <- true - close(done) + + fmt.Println("filled queue, starting workers") + + workers := 10 + for i := 0; i < workers; i++ { + go worker(queue, i, done) + } + + for { + if len(queue) == 0 { + done <- true + close(done) + close(queue) + break + } + time.Sleep(1 * time.Second) + } newMeta := utterancesToFileTextMap(utterances) writeCSV(mapToCSV(newMeta)) } -- cgit v1.2.3