Skip to content

Commit ce45744

Browse files
committed
Mutex and sub dir fix
1 parent 1ef1b8d commit ce45744

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

parser/academicCalendars.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,15 @@ PDF Content:
7373

7474
func ParseAcademicCalendars(inDir string, outDir string) {
7575
// Get sub folder from output folder
76-
outSubDir := filepath.Join(outDir, "academicCalendars")
76+
inSubDir := filepath.Join(inDir, "academicCalendars")
7777

7878
result := []schema.AcademicCalendar{}
7979

8080
// Parallel requests
8181
numWorkers := 10
8282
jobs := make(chan string)
8383
var wg sync.WaitGroup
84+
var mu sync.Mutex
8485

8586
// Start worker goroutines
8687
for range numWorkers {
@@ -94,14 +95,17 @@ func ParseAcademicCalendars(inDir string, outDir string) {
9495
if err != nil {
9596
panic(err)
9697
}
98+
99+
mu.Lock()
97100
result = append(result, academicCalendar)
101+
mu.Unlock()
98102

99103
log.Printf("Parsed %s!", filepath.Base(path))
100104
}
101105
}()
102106
}
103107

104-
err := filepath.WalkDir(outSubDir, func(path string, d fs.DirEntry, err error) error {
108+
err := filepath.WalkDir(inSubDir, func(path string, d fs.DirEntry, err error) error {
105109
if err != nil {
106110
return err
107111
}

0 commit comments

Comments
 (0)