GithubHelp home page GithubHelp logo

workerCache 没有初始化 about ants HOT 4 CLOSED

panjf2000 avatar panjf2000 commented on August 28, 2024
workerCache 没有初始化

from ants.

Comments (4)

panjf2000 avatar panjf2000 commented on August 28, 2024

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

from ants.

choleraehyq avatar choleraehyq commented on August 28, 2024

这个算是个风格问题吧,设了 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 里。

from ants.

panjf2000 avatar panjf2000 commented on August 28, 2024

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

from ants.

choleraehyq avatar choleraehyq commented on August 28, 2024

ok, 那我就 close

from ants.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.