Channel not working as expected

There are multiple Add and delete buttons on the local GUI. Once I click on the add/delete button from GUI then I am getting button active button IDs in the form of array through the “mainHandler” handler.

Then I am extracting each ID from array and do some processing. The processing should continue periodically (lets say every 60 seconds) for each ID. This will be for infinite time.

Once I click on Add/Delete button then again I will get complete list of all active IDs again and I need to do processing only on those IDs. But sometimes the main thread is not getting called when I add/delete list from local GUI.

If I comment go c.func1() function then I am able to receive data every time in the handler if it is updated from local GUI.

Code Snippet:

type DataTable struct {
Exit chan struct{}
DataList []string

var dataTable *DataTable
func (c *controller) mainHandler(mc xxxx) {
if dataTable == nil {
dataTable = &DataTable{}
} else {
dataTable.Exit <- struct{}{}
r := mc.BodyReader()
dataTable.DataList = r.GetSliceOfString(“data”) // Updating IDs in the slice
go c.func1()

func (c *controller) func1() {
for {
select {
case <-time.After(60 * time.Second):
c.func2() // The processing will be done on dataTable.DataList inside this function. Sometimes this function took 10 seconds to complete the opration.
case <-dataTable.Exit:

It is not clear if we are talking about “web grids”. I use ag-Grid instead of dataTable.

If we are talking about data grids, I found that involving Go in this case many things gets slower. I decided to use AJAX instead of Go. CSR instead of SSR.

Please find the code at below:

When I send the quit <- true signal, the go routine should stop immediately but it is not stopping.

Please let me know if anything wrong in the program.

The use case is to stop go routine immediately.

You have to call test function as go routine. Otherwise program goes as indefinite loop.

1 Like

go testFunc()
Works ?

1 Like

I think this code of “A tour of Google” show what @Gowtham_Girithar and @ani say about go testFunc()

A select blocks until one of its cases can run, then it executes that case. It chooses one at random if multiple are ready

Yes. Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.