我怎么知道一个门厅是否完成,没有阻塞?(How do I find out if a goroutine is done, without blocking?)
到目前为止,我见过的所有例子都涉及阻塞来获取结果(通过<-chan运算符)。
我目前的做法涉及将指针传递给结构:
type goresult struct { result resultType; finished bool; }该门厅在完成时写入。 然后,只要方便,就可以finished检查。 你有更好的选择吗?
我真正想要的是一个Qt风格的信号插槽系统。 我有预感,解决方案看起来几乎微不足道(有很多未知的潜力),但我还不熟悉这门语言。
All the examples I've seen so far involve blocking to get the result (via the <-chan operator).
My current approach involves passing a pointer to a struct:
type goresult struct { result resultType; finished bool; }which the goroutine writes upon completion. Then it's a simple matter of checking finished whenever convenient. Do you have better alternatives?
What I'm really aiming for is a Qt-style signal-slot system. I have a hunch the solution will look almost trivial (chans have lots of unexplored potential), but I'm not yet familiar enough with the language to figure it out.
最满意答案
你可以使用“逗号,好的”模式(参见他们的“ 有效的去 ”页面):
foo := <- ch; // This blocks. foo, ok := <- ch; // This returns immediately.You can use the "comma, ok" pattern (see their page on "effective go"):
foo := <- ch; // This blocks. foo, ok := <- ch; // This returns immediately.#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
上一篇:战争的蚂蚁召唤序列(Ant call sequence for war)
下一篇:您的SQL语法有错误;(You have an error in your SQL syntax; creating a trigger in Joomla)
推荐阅读
留言与评论(共有 14 条评论) |
本站网友 血浆蛋白 | 28分钟前 发表 |
= <- ch; // This returns immediately. | |
本站网友 交易系统 | 12分钟前 发表 |
= <- ch; // This returns immediately. You can use the "comma | |
本站网友 wwwhao123com | 22分钟前 发表 |
我见过的所有例子都涉及阻塞来获取结果(通过<-chan运算符) | |
本站网友 寿光房产网 | 13分钟前 发表 |
= <- ch; // This blocks. foo | |
本站网友 脑溢血前兆 | 29分钟前 发表 |
type goresult struct { result resultType; finished bool; } which the goroutine writes upon completion. Then it's a simple matter of checking finished whenever convenient. Do you have better alternatives? What I'm really aiming for is a Qt-style signal-slot system. I have a hunch the solution will look almost trivial (chans have lots of unexplored potential) | |
本站网友 东方冠郡 | 15分钟前 发表 |
All the examples I've seen so far involve blocking to get the result (via the <-chan operator). My current approach involves passing a pointer to a struct | |
本站网友 乳房整形对比图 | 30分钟前 发表 |
All the examples I've seen so far involve blocking to get the result (via the <-chan operator). My current approach involves passing a pointer to a struct | |
本站网友 衡阳房 | 5分钟前 发表 |
只要方便 | |
本站网友 wap游戏 | 4分钟前 发表 |
but I'm not yet familiar enough with the language to figure it out. 最满意答案 你可以使用“逗号 | |
本站网友 鱼尾纹怎么去 | 14分钟前 发表 |
ok | |
本站网友 思月书院 | 0秒前 发表 |
但我还不熟悉这门语言 | |
本站网友 日照楼盘 | 8分钟前 发表 |
然后 | |
本站网友 抑郁症自我治疗方法 | 28分钟前 发表 |
我怎么知道一个门厅是否完成 |