当前位置:网站首页>Go从入门到实战——Context与任务取消(笔记)
Go从入门到实战——Context与任务取消(笔记)
2022-06-27 19:22:00 【积淀 ytu】
关联任务的取消

Context

func isCancelled(ctx context.Context) bool {
select {
case <-ctx.Done():
return true
default:
return false
}
}
func TestCancel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
for i := 0; i < 5; i++ {
go func(i int, ctx context.Context) {
for {
if isCancelled(ctx) {
break
}
time.Sleep(time.Millisecond * 5)
}
fmt.Println(i, "Done")
}(i, ctx)
}
cancel()
time.Sleep(time.Second * 1)
}

边栏推荐
- Modify large online games through CE modifier
- 让马化腾失望了!Web3.0,毫无希望
- 一套系统,减轻人流集中地10倍的通行压力
- VMware vSphere esxi 7.0 installation tutorial
- Love math experiment | phase 9 - intelligent health diagnosis using machine learning method
- 今晚战码先锋润和赛道第2期直播丨如何参与OpenHarmony代码贡献
- OpenSSL 编程 二:搭建 CA
- 非常全面的DolphinScheduler(海豚调度)安装使用文档
- Save method of JPA stepping pit series
- 开启生态新姿势 | 使用 WrodPress 远程附件存储到 COS
猜你喜欢

行业案例|从零售之王看银行数字化转型的运营之道
![Unleash the innovative power of open source database | [Gansu] opengauss meetup has come to a successful conclusion](/img/21/9c5f5122270adea9444ff5f2d199ed.jpg)
Unleash the innovative power of open source database | [Gansu] opengauss meetup has come to a successful conclusion

Oracle的CTAS能不能将约束等属性带到新表?

Codeforces Global Round 14

KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"

Ceph分布式存储

Use the storcli tool to configure raid. Just collect this article

Can Oracle's CTAs bring constraints and other attributes to the new table?

GoLand permanently activated

MySQL usage notes 1
随机推荐
小王的面试训练任务
Covering access to 2w+ traffic monitoring equipment, EMQ creates a new digital engine for all elements of traffic in Shenzhen
GoLand permanently activated
农产品期货怎么做怎么开户,期货开户手续费多少,找谁能优惠手续费?
KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"
PCIE知识点-008:PCIE switch的结构
分享|智慧环保-生态文明信息化解决方案(附PDF)
CEPH distributed storage
ARCS模型介绍
实际工作中用到的shell命令 - sed
爱数课实验 | 第七期-基于随机森林的金融危机分析
MySQL client tools are recommended. I can't imagine that it is best to use Juran
关于企业数字化的展望(38/100)
GFS distributed file system
送你12个常用函数公式,用过的都说好
ICML2022 | 可扩展深度高斯马尔可夫随机场
数据平台调度升级改造 | 从Azkaban 平滑过度到Apache DolphinScheduler 的操作实践
100 important knowledge points that SQL must master: sorting and retrieving data
Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
Codeforces Round #722 (Div. 2)