Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.PoolWithFunc has no field or method Serve #88

Closed
huangp0600 opened this issue Apr 27, 2020 · 4 comments
Closed

v2.PoolWithFunc has no field or method Serve #88

huangp0600 opened this issue Apr 27, 2020 · 4 comments
Assignees
Labels
duplicate This issue or pull request already exists help wanted Extra attention is needed question Further information is requested

Comments

@huangp0600
Copy link

huangp0600 commented Apr 27, 2020

I encounter some build problems, hinting "myPool.Serve undefined (type *v2.PoolWithFunc has no field or method Serve)"

import (
	"fmt"
	"strconv"
	"time"
	"github.com/panjf2000/ants/v2"
)


var tunnel = make(chan string, 1)
func main() {

	//push something to tunnel

	myPool, _ := ants.NewPoolWithFunc(3, Myfunc)
	defer myPool.Release()

	for {
		select {
		case a := <-tunnel:
			go myPool.Serve(a)
		}
	}
}

@huangp0600 huangp0600 added help wanted Extra attention is needed question Further information is requested labels Apr 27, 2020
@panjf2000
Copy link
Owner

Which version of ants were you using? There is already no Serve method in v2, it is Invoke now, please read the doc more carefully.

@panjf2000
Copy link
Owner

BTY, you are using ants in a wrong way, there is no need to submit a task to pool in a new goroutine, you're already using a goroutine pool, why did you still have to use go to submit task to pool, it makes no sense here, just call pool.Invoke directly.

@huangp0600
Copy link
Author

Thanks for quick response. Ants provides a great experience when writing concurrent code.
I have another question,
if Myfunc has more than one parameters, how should I call myPool, _ := ants.NewPoolWithFunc(3, Myfunc)?
I checked the declaration of NewPoolWithFunc, it seems like pf only accept one parameter.

func NewPoolWithFunc(size int, pf func(interface{}), options ...Option)

thanks in advance

import (
	"fmt"
	"strconv"
	"time"
	"github.com/panjf2000/ants/v2"
)


var tunnel = make(chan string, 1)
func main() {

	//push something to tunnel

	myPool, _ := ants.NewPoolWithFunc(3, Myfunc)
	defer myPool.Release()

	for {
		select {
		case a := <-tunnel:
			myPool.Invoke(a)
		}
	}
}

@panjf2000
Copy link
Owner

#81

@panjf2000 panjf2000 added the duplicate This issue or pull request already exists label Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants