summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrailFinder <wohilas@gmail.com>2023-02-16 14:55:19 +0300
committerGrailFinder <wohilas@gmail.com>2023-02-16 14:55:19 +0300
commit6a3467e034798fa1153170fadb0aab50fac9f640 (patch)
tree85b468e34a6c066c27ff0cf02ecf9bf4e229e004
parent08f3748a34fe4d7d42da4670c8c46b7b73fbb720 (diff)
Enha: try concurrency
-rw-r--r--main.go27
1 files changed, 19 insertions, 8 deletions
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))
}