}
func main() {
// Create a buffered (non-blocking) pool that can scale up to 100 workers
// and has a buffer capacity of 1000 tasks
pool := pond.New(5, 1000, pond.MinWorkers(5))
// Submit 1000 tasks
for i := 1; i < 1000; i++ {
n := i
pool.Submit(func() {
testPool(n, pool)
})
}
// pool.RunningWorkers()
// Stop the pool and wait for all submitted tasks to complete
fmt.Println("wait all task done ...")
pool.StopAndWait()
}
package main
import (
"fmt"
"github.com/alitto/pond"
"time"
)
func testPool(i int, p *pond.WorkerPool) {
if i == 8 {
var stop string
// fmt.Printf("stop -- %d : ", i)
// fmt.Scanln(&stop)
stop = "yes"
if stop == "yes" {
fmt.Println("stop ok")
p.Stop()
return
}
}
func main() {
// Create a buffered (non-blocking) pool that can scale up to 100 workers
// and has a buffer capacity of 1000 tasks
pool := pond.New(5, 1000, pond.MinWorkers(5))
// Submit 1000 tasks
for i := 1; i < 1000; i++ {
n := i
pool.Submit(func() {
testPool(n, pool)
})
}
// pool.RunningWorkers()
// Stop the pool and wait for all submitted tasks to complete
fmt.Println("wait all task done ...")
pool.StopAndWait()
}
output :
run 1
run 3
run 2
wait all task done ...
run 4
run 5
run 6
run 7
stop ok
run 9
run 10
fatal error: all goroutines are asleep - deadlock!
test demo : package main
import ( "fmt" "github.com/alitto/pond" "time" )
func testPool(i int, p *pond.WorkerPool) { if i == 8 { var stop string // fmt.Printf("stop -- %d : ", i) // fmt.Scanln(&stop) stop = "yes" if stop == "yes" { fmt.Println("stop ok") p.Stop() return }
} func main() { // Create a buffered (non-blocking) pool that can scale up to 100 workers // and has a buffer capacity of 1000 tasks pool := pond.New(5, 1000, pond.MinWorkers(5))
} package main
import ( "fmt" "github.com/alitto/pond" "time" )
func testPool(i int, p *pond.WorkerPool) { if i == 8 { var stop string // fmt.Printf("stop -- %d : ", i) // fmt.Scanln(&stop) stop = "yes" if stop == "yes" { fmt.Println("stop ok") p.Stop() return }
} func main() { // Create a buffered (non-blocking) pool that can scale up to 100 workers // and has a buffer capacity of 1000 tasks pool := pond.New(5, 1000, pond.MinWorkers(5))
} output : run 1 run 3 run 2 wait all task done ... run 4 run 5 run 6 run 7 stop ok run 9 run 10 fatal error: all goroutines are asleep - deadlock!