go第三方库-github.com.panjf2000.ants
Contents
ants是一个开源的go协程池(goruntine池)。使用很方便。
简单使用
使用ants默认的协程池
|
|
通常和sync.waitgroup一起使用。在main里面使用wg.Add()和wg.Wait,然后在函数中使用wg.Done()。
自定义池
自定义一个协程池,支持选项模式配置,具体看官网
|
|
释放和重启pool
协程池需要被释放,通常和defer配合使用
|
|
之前销毁的池可以通过重启来重新激活
|
|
通过函数构造池
直接生成专门调用某个函数的协程池
|
|
调用协程
|
|