<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'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'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'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传