dean2021 / hackpool

优雅的go协程库,轻松控制并发数

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HackPool

北半球最优雅的协程池

Example

package main

import (
	"fmt"
	"github.com/poc-db/hackpool"
)

func main() {

	concurrency := 2   // 并发数
	taskCount := 100   

	hp := hackpool.New(concurrency, func(i interface{}) {
		fmt.Println(i.(int))
	})

	go func() {

		for i := 0; i < taskCount; i++ {
			hp.Push(i)
		}

		// 必须关闭,不然阻塞死锁
		hp.Close()
	}()

	// 跑起来! 伙计
	hp.Run()
}

Installation

go get github.com/poc-db/hackpool

License

This project is copyleft of CSOIO and released under the GPL 3 license.

About

优雅的go协程库,轻松控制并发数


Languages

Language:Go 100.0%