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

workerCache 没有初始化 #52

Closed
choleraehyq opened this issue Sep 11, 2019 · 4 comments
Closed

workerCache 没有初始化 #52

choleraehyq opened this issue Sep 11, 2019 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@choleraehyq
Copy link
Contributor

Describe the bug
A clear and concise description of what the bug is.
没有设置 New 函数,这个是忘了还是有什么玄机呢
To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Error messages/Trace logs
If applicable, add some logs to help explain your problem.

System info (please complete the following information):

  • OS: [e.g. linux, macOS]
  • Go Version [e.g. 1.12]

Additional context
Add any other context about the problem here.

@choleraehyq choleraehyq added the bug Something isn't working label Sep 11, 2019
@panjf2000
Copy link
Owner

为什么要设置New,我想不到有什么必要性。

@choleraehyq
Copy link
Contributor Author

这个算是个风格问题吧,设了 New 你就不需要写

if cacheWorker := p.workerCache.Get(); cacheWorker != nil {
			w = cacheWorker.(*goWorkerWithFunc)
		} else {
			w = &goWorkerWithFunc{
				pool: p,
				args: make(chan interface{}, workerChanCap),
			}
		}

了。我是觉得既然用了 Pool,那用 New 就很自然,像现在这种代码会让人费解,会让人怀疑是不是别的地方会把 nil put 到 Pool 里。

@panjf2000
Copy link
Owner

panjf2000 commented Sep 11, 2019

哦,你说的是这个意思啊,是这样的,设置了New之后,调用workerCache.get()无法从代码结构上知道得到的 worker 是缓存的还是新建的,这不用New而用 if else 之前是想着后面可能会在这个 if 判断的不同分支里做一些其他的东西(虽然到现在好像也还没想到有什么可做的东西),所以其实我倒觉得无所谓了,两种做法都 ok 😂

@panjf2000 panjf2000 added question Further information is requested and removed bug Something isn't working labels Sep 11, 2019
@choleraehyq
Copy link
Contributor Author

ok, 那我就 close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants