Skip to content

boxungo/gopool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gopool

结构

                         ┌ Worker
                         ├ ...
Task --> Job Channel --> ├ Worker
                         ├ ...
                         └ Worker

示例

package main
import (
    "fmt"
    "time"

    "github.com/boxungo/gopool"
)

func main() {
    poolOpt := gopool.Option{
        MaxWorkers: 2,
        MaxJobs: 0,
    }
    pool := gopool.NewPool(option)

    for i := 0; i < 10; i++ {
        out := fmt.Sprintf("Job: %d", i)
        job := gopool.NewJob(func() {
            fmt.Println(out)
        })
        pool.Submit(job)
    }

    time.Sleep(time.Second * 10)
}