Skip to content

Commit

Permalink
Files generated with Goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarballadares committed May 13, 2015
1 parent c6629e1 commit 9f46196
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
16 changes: 12 additions & 4 deletions fluxscaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ func main() {
actionGenerator := ResourceGenerator{&Action{ResourceOptions(resourceOptions)}}
storeGenerator := ResourceGenerator{&Store{ResourceOptions(resourceOptions)}}

constantGenerator.Execute()
actionGenerator.Execute()
storeGenerator.Execute()
routines := 3;
race := make(chan bool)

go constantGenerator.Execute(race)
go actionGenerator.Execute(race)
go storeGenerator.Execute(race)

if (isApi) {
routines++
apiGenerator := ResourceGenerator{&Api{ResourceOptions(resourceOptions)}}
apiGenerator.Execute()
go apiGenerator.Execute(race)
}

for i:= 0; i < routines; i++ {
<- race
}
}
21 changes: 15 additions & 6 deletions resource-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,38 @@ package main

import (
"fmt"
"os"
)

type ResourceGenerator struct {
Res ResourceInterface
}

func (rg *ResourceGenerator) Execute() {
rg.createDirIfNotExists()
func (rg *ResourceGenerator) Execute(race chan<- bool) bool {
if _, err := rg.createDirIfNotExists(); err != nil {
fmt.Println("Unexpected error while checking ", rg.Res.GetDir(), err)
race <- true
return false
}

rg.createFileIfNotExists()
race <- true
return true
}

func (rg *ResourceGenerator) createDirIfNotExists() {
func (rg *ResourceGenerator) createDirIfNotExists() (bool, error) {
fullDirPath := GetFullDirPath(rg.Res.GetDir())
exists, err := PathExists(fullDirPath)

if err != nil {
fmt.Println("Unexpected error while checking ", rg.Res.GetDir(), err)
os.Exit(1)
return false, err
}

if exists == false {
CreateDir(fullDirPath)

return true, nil
} else {
return false, nil
}
}

Expand Down

0 comments on commit 9f46196

Please sign in to comment.