added sem simple worker pool

This commit is contained in:
Jian Han 2017-12-03 15:50:40 +10:00
parent d3bce4731b
commit 5d35abc39d
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package main
import (
"fmt"
"time"
)
func main() {
concurrentCount := 5
sem := make(chan bool, concurrentCount)
for i := 0; i < 100; i++ {
sem <- true
go func(i int) {
dummyProcess(i)
<-sem
}(i)
}
time.Sleep(time.Second * 20)
}
func dummyProcess(i int) {
fmt.Printf("Process Dummy %v \n", i)
time.Sleep(time.Second)
}

27
urfavecli/main.go Normal file
View File

@ -0,0 +1,27 @@
package main
import (
"fmt"
"os"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "hello_cli"
app.Usage = "Print hello world"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "name, n",
Value: "World",
Usage: "Who to say hello to.",
},
}
app.Action = func(c *cli.Context) error {
name := c.GlobalString("name")
fmt.Printf("Hello %s!\n", name)
return nil
}
app.Run(os.Args)
}