forked from struffel/simple-deflicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
45 lines (42 loc) · 916 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"github.com/gosuri/uiprogress"
"github.com/inancgumus/screen"
)
func forEveryPicture(pictures []picture, progressBar *uiprogress.Bar, threads int, f func(pic picture) (picture, error)) ([]picture, error) {
tokens := make(chan error, threads)
var err error
for i := 0; i < threads; i++ {
tokens <- nil
}
for i := range pictures {
err = <-tokens
if err != nil {
return pictures, err
}
go func(i int) {
var functionError error
defer func() {
progressBar.Incr()
tokens <- functionError
}()
pictures[i], functionError = f(pictures[i])
}(i)
}
for i := 0; i < threads; i++ {
err = <-tokens
if err != nil {
return pictures, err
}
}
return pictures, nil
}
func printInfo() {
fmt.Println("SIMPLE DEFLICKER")
fmt.Println("v0.3.0 / github.com/StruffelProductions/simple-deflicker")
}
func clear() {
screen.MoveTopLeft()
screen.Clear()
}