Add more examples
This commit is contained in:
@@ -8,7 +8,8 @@ import (
|
||||
|
||||
func main() {
|
||||
|
||||
// Create a pool with 100 workers
|
||||
// Create a buffered (non-blocking) pool that can scale up to 100 workers
|
||||
// and has a buffer capacity of 1000 tasks
|
||||
pool := pond.New(100, 1000)
|
||||
|
||||
// Submit 1000 tasks
|
||||
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/alitto/pond"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Create an unbuffered (blocking) pool with a fixed
|
||||
// number of workers
|
||||
pool := pond.New(10, 0, pond.MinWorkers(10))
|
||||
|
||||
// Submit 1000 tasks
|
||||
for i := 0; i < 1000; i++ {
|
||||
n := i
|
||||
pool.Submit(func() {
|
||||
fmt.Printf("Running task #%d\n", n)
|
||||
})
|
||||
}
|
||||
|
||||
// Stop the pool and wait for all submitted tasks to complete
|
||||
pool.StopAndWait()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/alitto/pond"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Create a pool
|
||||
pool := pond.New(10, 1000)
|
||||
defer pool.StopAndWait()
|
||||
|
||||
// Create a task group
|
||||
group := pool.Group()
|
||||
|
||||
// Submit a group of related tasks
|
||||
for i := 0; i < 20; i++ {
|
||||
n := i
|
||||
group.Submit(func() {
|
||||
fmt.Printf("Running group task #%d\n", n)
|
||||
})
|
||||
}
|
||||
|
||||
// Wait for all tasks in the group to complete
|
||||
group.Wait()
|
||||
}
|
||||
Reference in New Issue
Block a user