Skip to content

Commit

Permalink
fixed Concurrency issue with Images left in batch proccesing
Browse files Browse the repository at this point in the history
  • Loading branch information
Achno committed Aug 1, 2024
1 parent ad92b8e commit fb4d68a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"
"sync"
"sync/atomic"

"github.com/Achno/gowall/utils"

Expand Down Expand Up @@ -128,6 +129,7 @@ func ProcessImg(imgPath string, processor ImageProcessor,theme string ) error {
func ProcessBatchImgs(files []string , theme string, processor ImageProcessor){

var wg sync.WaitGroup
var remaining int32 = int32(len(files))

for index, file := range files{

Expand All @@ -141,8 +143,8 @@ func ProcessBatchImgs(files []string , theme string, processor ImageProcessor){
if ok != nil {
os.Exit(1)
}
// TODO fix the index / concurency issue
fmt.Printf(" ::: Image %d Completed , %d Images left ::: \n",index,len(files) -index -1)
remainingCount := atomic.AddInt32(&remaining, -1)
fmt.Printf(" ::: Image %d Completed , %d Images left ::: \n",index,remainingCount)
}(file,index)

}
Expand Down

0 comments on commit fb4d68a

Please sign in to comment.