Progress checking for goroutines workers?

blov · 2017-04-19 07:00:04 · 573 次点击    
这是一个分享于 2017-04-19 07:00:04 的资源,其中的信息可能已经有所发展或是发生改变。

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.

What would be the general approach to implement such feature?


评论:

echophant:

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.

tmornini:

An alternative to /u/echophant 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.

thucle:

Hi @Nzzy, the idea you can use the channel you keep the status of goroutine. You can check at https://play.golang.org/p/yHkjO9lFbE .

You can use many channels for many goroutines or one channel for many goroutines with data format to recognize the goroutine's identify.


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

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