summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go14
-rw-r--r--model/new.go60
2 files changed, 44 insertions, 30 deletions
diff --git a/main.go b/main.go
index 5a1bdd3..a393a40 100644
--- a/main.go
+++ b/main.go
@@ -19,6 +19,7 @@ import (
"pik/runner/shell"
"pik/search"
"pik/spool"
+ "sync"
)
var initializers = []model.Initializer{
@@ -58,12 +59,17 @@ func main() {
os.Exit(0)
}
+ wg := sync.WaitGroup{}
for _, i := range initializers {
- err := i.Init()
- if err != nil {
- _, _ = spool.Warn("%v\n", err)
- }
+ wg.Go(func() {
+ err := i.Init()
+ if err != nil {
+ _, _ = spool.Warn("%v\n", err)
+ }
+ })
}
+ wg.Wait()
+
here, err := os.Getwd()
if err != nil {
_, _ = spool.Warn("%v\n", err)
diff --git a/model/new.go b/model/new.go
index c2d5e37..e23bbf6 100644
--- a/model/new.go
+++ b/model/new.go
@@ -6,44 +6,52 @@ import (
"path/filepath"
"pik/identity"
"strings"
+ "sync"
)
func NewState(f fs.FS, locations []string, indexers []Indexer, runners []Runner) (*State, []error) {
var errs []error
st := &State{}
+ wg := sync.WaitGroup{}
for _, loc := range locations {
- _, dirName := filepath.Split(loc)
- src := &Source{
- Path: loc,
- Identity: identity.New(dirName),
- }
- loc = strings.TrimSuffix(loc, "/")
- loc = strings.TrimPrefix(loc, "/")
-
- if loc == "" {
- continue
- }
-
- for _, indexer := range indexers {
+ wg.Go(func() {
+ _, dirName := filepath.Split(loc)
+ src := &Source{
+ Path: loc,
+ Identity: identity.New(dirName),
+ }
+ loc = strings.TrimSuffix(loc, "/")
+ loc = strings.TrimPrefix(loc, "/")
- s, err := fs.Sub(f, loc)
- if err != nil && !errors.Is(err, fs.ErrNotExist) {
- errs = append(errs, err)
- continue
+ if loc == "" {
+ return
}
- targets, err := indexer.Index("/"+loc, s, runners)
- if err != nil && !errors.Is(err, fs.ErrNotExist) {
- errs = append(errs, err)
- continue
+
+ myWg := sync.WaitGroup{}
+ for _, indexer := range indexers {
+ myWg.Go(func() {
+ s, err := fs.Sub(f, loc)
+ if err != nil && !errors.Is(err, fs.ErrNotExist) {
+ errs = append(errs, err)
+ return
+ }
+ targets, err := indexer.Index("/"+loc, s, runners)
+ if err != nil && !errors.Is(err, fs.ErrNotExist) {
+ errs = append(errs, err)
+ return
+ }
+ src.Targets = append(src.Targets, targets...)
+ })
}
- src.Targets = append(src.Targets, targets...)
- }
+ myWg.Wait()
- if src.Targets != nil {
- st.Sources = append(st.Sources, src)
- }
+ if src.Targets != nil {
+ st.Sources = append(st.Sources, src)
+ }
+ })
}
+ wg.Wait()
return st, errs
}