go-do-work icon indicating copy to clipboard operation
go-do-work copied to clipboard

About Batch code example, something is wrong?

Open pathbox opened this issue 7 years ago • 1 comments

Hi~ I read the README.md of go-do-work. About Batch code example, something is wrong?

type adder struct {
	count uint32
}

func (a adder) DoWork() {
	a.count++
	time.Sleep(1 * time.Second)
}

func main() {
	test := adder{count: 0}
	pool := NewWorkerPool(3)   // Here is wrong? 
	defer pool.Close()
	batch1 := pool.NewTempBatch()
	batch2 := pool.NewTempBatch()
	pool.NewBatch("my batch")
	defer batch1.Clean()
	defer batch2.Clean()
	defer pool.CleanBatch("my batch")
	batch1.Add(test, 5)
	batch2.Add(test, 10)
	batch3, _ := pool.LoadBatch("my batch")
	batch3.Add(test, 4)
	batch1.Wait()
	fmt.Println("batch 1 done")
	batch2.Wait()
	fmt.Println("batch 2 done")
	fmt.Println(pool.GetQueueDepth())
	pool.Wait() // includes jobs added through batches
}

Right:

pool := gdw.NewWorkerPool(3)

pathbox avatar Feb 03 '18 07:02 pathbox

Indeed, the package name is missing from the invocation. Feel free to open a PR!

c3mb0 avatar Feb 04 '18 09:02 c3mb0