<p>This is probably not a Go specific question, but currently I am trying to display the progress for each goroutine worker in the frontend. The individual task is mainly calling external APIs and process those data into a database.</p>
<p>What would be the general approach to implement such feature?</p>
<hr/>**评论:**<br/><br/>echophant: <pre><p>At a high level, I would pass a status channel into the goroutine, and send an update from the worker on that channel when you have a meaningful update to report. Listen for those status channel updates and aggregate them as necessary, then display that in the frontend.</p></pre>tmornini: <pre><p>An alternative to <a href="/u/echophant" rel="nofollow">/u/echophant</a> is to have a function that creates a progress channel, spawns the worker goroutine, and returns the progress channel to the caller which can then monitor the channel for status updates.</p></pre>thucle: <pre><p>Hi @Nzzy, the idea you can use the channel you keep the status of goroutine. You can check at <a href="https://play.golang.org/p/yHkjO9lFbE" rel="nofollow">https://play.golang.org/p/yHkjO9lFbE</a> . </p>
<p>You can use many channels for many goroutines or one channel for many goroutines with data format to recognize the goroutine's identify.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传