mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-25 06:16:03 +03:00
added sem simple worker pool
This commit is contained in:
parent
d3bce4731b
commit
5d35abc39d
25
concurrency/simplesem/main.go
Normal file
25
concurrency/simplesem/main.go
Normal 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
27
urfavecli/main.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user