concurrent

package module
v0.0.0-...-4c90254 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2022 License: MIT Imports: 2 Imported by: 0

README

并发控制工具

    con := NewWorkerController(2)
	for i := 0; i < 100; i++ {
		con.Go(Helper(i)) //如何配合for 建议使用高阶函数绑定参数
	}
	con.Wait()


func Helper(i int) func() {
        return func() {
                log.Println(i)
                time.Sleep(time.Second)
				
        }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WorkerController

type WorkerController struct {
	// contains filtered or unexported fields
}

WorkerController 并发控制器

func NewWorkerController

func NewWorkerController(max int) *WorkerController

NewWorkerController 创建一个控制器

func (*WorkerController) Go

func (w *WorkerController) Go(f func())

Go 开启一个worker

func (*WorkerController) Wait

func (w *WorkerController) Wait()

Wait 等待所有worker完成

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL