Comments (4)
为什么要设置New
,我想不到有什么必要性。
from ants.
这个算是个风格问题吧,设了 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.
哦,你说的是这个意思啊,是这样的,设置了New
之后,调用workerCache.get()
无法从代码结构上知道得到的 worker 是缓存的还是新建的,这不用New
而用 if else 之前是想着后面可能会在这个 if 判断的不同分支里做一些其他的东西(虽然到现在好像也还没想到有什么可做的东西),所以其实我倒觉得无所谓了,两种做法都 ok 😂
from ants.
ok, 那我就 close
from ants.
Related Issues (20)
- Add option to turn off purgePeriodically HOT 3
- Add Working() method to get current number of busy goroutines HOT 2
- [Feature] Introduce the Future(like java) into ants. HOT 3
- why not check whether p.works has available worker before you spawn a new worker? HOT 1
- call ReleaseTimeout return ErrTimeout operation timed out, coroutine not released HOT 2
- [Feature]: Support resource partition HOT 2
- [Bug]: ticktock() goroutine memory leak
- [Question]: 主动kill任务 HOT 1
- [Bug]: ants.NewPoolWithFunc(1000, dorequest),当dorequest函数中不使用fmt.Println时,CPU耗尽;当使用打印函数时,CPU正常 HOT 6
- [Question]: can you please confirm the proper way for variables to be sent using ants? HOT 1
- [Question]: 清理过期worker一点疑问 HOT 1
- [Bug]: go.mod 中的go version(1.13)和ants.go存在不匹配 HOT 2
- [Bug]: Potential goroutine leak in pool.go HOT 3
- [Question]: How can I verifier the max goroutine count in pool is correct HOT 2
- [Question]: 为什么不提供一个任务包装,等待,获取任务结果 HOT 1
- [Question]: How to get meaningful statistics on a function pool? HOT 2
- [Question]: ants.Submit() question HOT 4
- [Question]: set max block task, but not return err when block task num more than set value HOT 1
- [Feature]: Add panicHandlerBuilder HOT 3
- [Question]: Can ants execute tasks in order? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ants.