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:
tmornini: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.
thucle: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.
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.
