Stopping a hanging call?

xuanbao · · 458 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello. Is there a way to have some call that hangs the system(like reading from a channel) stop if data hasn&#39;t been received in some time? Thank you.</p> <hr/>**评论:**<br/><br/>bastiaanvv: <pre><p>A very simple example on how to do this: <a href="https://play.golang.org/p/f4-pq0OQWvj" rel="nofollow">https://play.golang.org/p/f4-pq0OQWvj</a></p> <p>This method basically waits for two channels at the same time. The timeout channel and the int channel. Each time the int channel receives a value a new timeout is started. This simple method should be fine to use as long as you don&#39;t plan on receiving thousands of values per second.</p></pre>HarwellDekatron: <pre><p>This is the right answer.</p></pre>hell_0n_wheel: <pre><p>Yes.</p></pre>Hc3ttp3302: <pre><p>How?</p></pre>lausan: <pre><p><a href="https://golang.org/ref/spec#Select_statements" rel="nofollow"><code>select</code></a> and <a href="https://golang.org/pkg/time/#After" rel="nofollow"><code>time.After</code></a> could do it</p></pre>hell_0n_wheel: <pre><p><a href="http://www.catb.org/esr/faqs/smart-questions.html" rel="nofollow">http://www.catb.org/esr/faqs/smart-questions.html</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

458 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传