Skip to content

TimothyYe/gpool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gpool

A lightweight Goroutine worker pool, modified from grpool

Example

    runtime.GOMAXPROCS(runtime.NumCPU())

    // new a Goroutine pool with 100 workers and 50 job queue
    pool := gpool.NewPool(100, 50)
    defer pool.Release()

    // set 10 jobs that the pool should wait
    pool.WaitCount(10)

    // submit one or more jobs to pool
    for i := 0; i < 10; i++ {
        count := i

        pool.JobQueue <- func() {
            defer pool.JobDone()
            fmt.Printf("Pool job: %d\n", count)
        }
    }

    // wait until we call JobDone for all jobs
    pool.WaitAll()

License

MIT License

Releases

No releases published

Packages

No packages published

Languages