Comments (5)
之所以用ctx是想表达在成功调用ShutdownNow那一刻,所有处于“可中断上下文”中的go协程均能收到中断信号.这其中不仅包括了schedulingTasks任务调度循环,还包括那些运行中且内部监听了ctx信号的Task
func (b *OnDemandBlockTaskPool) schedulingTasks() {
// .....
// 这里向task传递的正是那个ctx,对于那些在内部监听了ctx.Done()的Task
// 使其以自定义方式更快速地中断运行
err := task.Run(b.ctx)
if err != nil {
return
}
}()
}
}
}
https://github.com/gotomicro/ekit/blob/dev/pool/task_pool.go#L253
from ekit.
👍
我试了一下别的方式,比如说使用 channel,确实不如这种方法好。
from ekit.
@longyue0521 @flycash 有几点疑问,请大佬指点:
1、NewOnDemandBlockTaskPool时用户必须使用WithQueueBacklogRate这个options来设置queueBacklogRate吗?否则if判断queueBacklogRate默认值为0,会创建失败吧?
2、372行注释不对吧(刚启动的协程除非恰巧赶上Shutdown/ShutdownNow被调用,否则应该至少执行一个task),如果initGo是10,用户只提交了2个任务,那剩余8个goroutine不会执行任务,所以不会至少执行一个task吧
from ekit.
- 既然设置为options,必然是可选的.即用户不通过WithXXXOption指定,在New的时候会提供默认值. 你可以看一下对应的测试代码,也可以在本地构造一个不设置queueBacklogRate而使NewOnDemandBlockTaskPool失败的测试用例
- 这个注释是用来说明,为什么刚刚创建idleTimer就要将其关闭,因为刚创建出来的协程很可能直接走for循环中的
case <-idleTimer.C
分支而退出. 那么这样耗时、耗资源创建出的协程却什么都没干是没有意义的.你举的用例是因为提供足够的任务,但也确实反映出该注视确实会引起歧义.你可以提交一个issue修改/完善该注释.
from ekit.
from ekit.
Related Issues (20)
- Tuple: 新增 Pair 和 Triple 两种类型 HOT 8
- retry: Strategy 接口设计与等间隔重试实现
- retry: 指数退避重试策略实现 HOT 1
- pool相关总issue
- sqlx:ScanRows 和 ScanAll方法 HOT 9
- mapx: MutipleTreeMap
- mapx: 为 MultipleMap 添加 PutVals 方法
- mapx: LinkedMap 特性 HOT 12
- copier: ReflectCopier 支持忽略字段 HOT 1
- copier: 支持类型转换 HOT 20
- randx: 随机验证码生成器 HOT 5
- ekit:AnyValue 支持类型转换 - String 转数字类型
- unsafe 转换 string 和 []byte HOT 1
- sqlx: sqlx.NewNullXXX 方法
- syncx: SegmentKeysLock HOT 3
- slice.ContainsFunc破坏性修改确认 HOT 3
- mapx: 支持 Len 方法
- 重构randx.RandCode以及传入的RandType数值 HOT 3
- slice 转 map HOT 3
- 提供 Must 和 MustT 函数,简化错误处理 HOT 4
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 ekit.