Stop running func on event

blov · · 471 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>How can i stop a running function that makes a series of operations in series? I would like to stop it on a channel event that could be sent or not. I need to run the series of operations only one time, so a for select block should seems unsuitable, but i don&#39;t know. How can i solve? </p> <hr/>**评论:**<br/><br/>itsmontoya: <pre><p>You can set an isClosed value for the iterating system. On loop, check if closed. If so, break out of loop</p></pre>Asoseil: <pre><p>how would you do it? can you add a simple example? maybe I didn&#39;t explain my problem well</p></pre>softwaregav: <pre><p>Can you show an example of how you would write your function that is doing the operations without considering cancellation?</p></pre>GentooMonk: <pre><p><a href="https://golang.org/pkg/context/" rel="nofollow">https://golang.org/pkg/context/</a></p></pre>dabshores: <pre><p>If the channel doesn&#39;t send the event, an empty <code>default:</code> case will allow the select statement to move on without blocking.</p></pre>

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

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