-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.go
More file actions
66 lines (51 loc) · 1.07 KB
/
table.go
File metadata and controls
66 lines (51 loc) · 1.07 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"log"
"sync"
f "github.com/soerlemans/table/filter"
u "github.com/soerlemans/table/util"
)
const (
// Lets prevent an unlimited amount of goroutines being kicked off.
MAX_TASKS = 10
)
// Orchestrate processing of different files.
func run(t_args Arguments) error {
tables, err := readInput(t_args)
if err != nil {
return err
}
filter, err := f.InitFilter(t_args.ProgramText)
if err != nil {
return err
}
var wg sync.WaitGroup
// TODO: Use taskCounter to decide on a max taskcount.
// var taskCounter uint64 = 0
for _, table := range tables {
// Use a lambda to capture localized variables.
task := func() {
// Create the context for the task to run.
ctx := initProcessContext(&filter, table)
// Start processing.
err := Process(ctx)
if err != nil {
log.Fatalln(err)
}
wg.Done()
}
// Increment wait count.
wg.Add(1)
// Launch async task.
go task()
}
// Wait for all goroutines to finish.
wg.Wait()
return nil
}
func main() {
args, err := initArgs()
u.FailIf(err)
err = run(args)
u.FailIf(err)
}