Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 730 Bytes

File metadata and controls

32 lines (23 loc) · 730 Bytes

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