TimothyYe / gpool

A lightweight Goroutine pool.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

A lightweight Goroutine pool.

License:MIT License


Languages

Language:Go 100.0%