zenthangplus/goccm

request

Closed this issue · 2 comments

goccm needs to export the concurrencyManager for a regular func to work: e.g.

func main() {
var ccm = goccm.New(10)
for int i = 0; i < 50; i++ {
ccm.Wait()
go myfunc(ccm)
}
// ....
ccm.WaitAllDone()
}

func myfunc(ccm *T) {
defer ccm.Done()
// doing some work ....
}

You can change your snippet like this (interface should be used):

package main

import (
	"fmt"

	"github.com/zenthangplus/goccm"
)

func main() {
	ccm := goccm.New(10)

	for i := 0; i < 50; i++ {
		ccm.Wait()

		go myfunc(i, ccm)
	}
	ccm.WaitAllDone()

}

func myfunc(i int, ccm goccm.ConcurrencyManager) {
	fmt.Printf("Running myfunc %d\n", i)
	defer ccm.Done()
}

However, I prefer avoid sending manager to function a parameter to have separated function logic and goroutine management.

Thanks for your comment, it already exposed an interface.