@@ -6,9 +6,13 @@ import (
66	"github.com/gookit/color" 
77	"github.com/karrick/godirwalk" 
88	"os" 
9+ 	"sync" 
910	"time" 
1011)
1112
13+ var  mu  sync.Mutex 
14+ var  wg  sync.WaitGroup 
15+ 
1216func  visit (osPathname  string , de  * godirwalk.Dirent ) error  {
1317	// we only process files 
1418	if  de .IsDir () {
@@ -33,16 +37,11 @@ func Watch(includedDirectories []string, watchFrequenceSeconds int, profile stri
3337	i  :=  0 
3438
3539	for  {
40+ 		wg .Add (len (includedDirectories ))
3641		for  _ , directoryToWalk  :=  range  includedDirectories  {
37- 			err  :=  godirwalk .Walk (directoryToWalk , & godirwalk.Options {
38- 				Callback : visit ,
39- 				Unsorted : true ,
40- 			})
41- 
42- 			if  err  !=  nil  {
43- 				panic (err )
44- 			}
42+ 			go  walkSingleDirectory (directoryToWalk )
4543		}
44+ 		wg .Wait ()
4645
4746		time .Sleep (time .Duration (watchFrequenceSeconds ) *  time .Second )
4847
@@ -55,6 +54,20 @@ func Watch(includedDirectories []string, watchFrequenceSeconds int, profile stri
5554	}
5655}
5756
57+ func  walkSingleDirectory (directoryToWalk  string ) {
58+ 	mu .Lock ()
59+ 	defer  mu .Unlock ()
60+ 	defer  wg .Done ()
61+ 	err  :=  godirwalk .Walk (directoryToWalk , & godirwalk.Options {
62+ 		Callback : visit ,
63+ 		Unsorted : true ,
64+ 	})
65+ 
66+ 	if  err  !=  nil  {
67+ 		panic (err )
68+ 	}
69+ }
70+ 
5871func  isFileChanged (path  string ) bool  {
5972	fileInfo , err  :=  os .Stat (path )
6073
@@ -98,6 +111,8 @@ func isFileChanged(path string) bool {
98111}
99112
100113func  garbageCollection () {
114+ 	mu .Lock ()
115+ 	defer  mu .Unlock ()
101116	for  path , _  :=  range  fileMap  {
102117		if  ! util .FileExists (path ) {
103118			delete (fileMap , path )
0 commit comments