mirror of
https://github.com/nxshock/gwp.git
synced 2024-11-27 03:31:02 +05:00
Add code example
This commit is contained in:
parent
5c3a623f18
commit
b9155d15d3
38
README.md
38
README.md
@ -3,3 +3,41 @@
|
||||
Simple goroutine worker pool written in Go.
|
||||
|
||||
Status: Work in progress.
|
||||
|
||||
Example:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/nxshock/gwp"
|
||||
)
|
||||
|
||||
// Job function
|
||||
func f(i int) error {
|
||||
log.Printf("Job №%d", i)
|
||||
|
||||
// Simulate work
|
||||
time.Sleep(time.Second)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
worker := gwp.New(4)
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
n := i
|
||||
// Send job
|
||||
worker.Add(func() error {
|
||||
return f(n)
|
||||
})
|
||||
}
|
||||
|
||||
// Wait all jobs to complete
|
||||
worker.CloseAndWait()
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user