Comments (2)
是的 可能存在这个问题 我仔细看看在回复你哈
from easy-tips.
可以在消费者超时结束后通知生产者无需发送处理结果:
func run(wg *sync.WaitGroup, stopChan chan struct{}) {
defer wg.Done()
ch := make(chan string)
wg.Add(1)
go func() {
defer wg.Done()
time.Sleep(9 * time.Second)
select {
case ch <- "work1":
fmt.Println("i'm work")
return
case <-stopChan:
fmt.Println("i has been stopped")
return
}
}()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
select {
case res := <-ch:
fmt.Println("get a work: ", res)
return
case <-ctx.Done():
select {
case stopChan <- struct{}{}:
default:
}
fmt.Println("ctx err : ", ctx.Err())
return
}
}
from easy-tips.
Related Issues (20)
- 悲观锁 HOT 8
- English version HOT 1
- 关于设计模式中单例模式的意见 HOT 1
- 有歧义的变量命名 HOT 2
- [英文版翻译申请] HOT 8
- 数据结构 HOT 1
- 感觉之前提过的代码都不见了啊。。 HOT 3
- TIGERB/easy-tips/php/artisan.md 文件中关于使用匿名函数代码错误 HOT 3
- 引擎部分,聚簇索引上下文介绍不一致 HOT 4
- easy-tips/patterns/builder/ 建造者模式有错误,方法名字不对 HOT 2
- 悲观锁执行超时处理 HOT 1
- 设计模式 HOT 1
- 单利模式 HOT 1
- TIGERB------ HOT 1
- 为什么作者的设计模式25种 HOT 3
- 老哥,最近更新很慢啊 HOT 1
- 再通过list生成map时可通过内置函数实现 HOT 1
- tcp/ip网络模型想补充下 HOT 1
- Magic method access test 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 easy-tips.