--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
What do you see when you run it? I see:
finished 1
finished 2
len > %!s(int=2) ç Using a string format for an int
Name > 1
Name > 2
Ø Work 2 - have 3 second
I’m not sure exactly what you are trying to do, but I suspect that changing “messges” to hold 2 items might make it work.
messges := make(chan *TestStruct, 2)
I’m guessing, but I suspect that you didn’t realize that if Work1 runs first, then Work2 will block since the channel is full (or until you close it).
John
John Souvestre - New Orleans LA
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Hi Abhi.
I believe that the wait group timeout (in monitorWorker) was set to 2 seconds in the code you posted.
I put a debugging print in the timeout case, and it is taking place.
What were you expecting to see?
Hi again.
Did you perhaps intend to make the call to monitorWorker() as a goroutine? That would let it run in parallel with the rest of main.
John
John Souvestre - New Orleans LA
From: John Souvestre [mailto:Jo...@Souvestre.com]
Sent: 2017 January 08, Sun 06:10
To: 'golang-nuts'
Subject: RE: [go-nuts] Multiple goroutine timeout for waitgroup not working
Hi Abhi.
I believe that the wait group timeout (in monitorWorker) was set to 2 seconds in the code you posted.
I put a debugging print in the timeout case, and it is taking place.
What were you expecting to see?
John
John Souvestre - New Orleans LA
Sent: 2017 January 08, Sun 05:48
To: golang-nuts
so output of below should be Len = 1 and should print only work 1 only and not 2 ( as work 2 is timed out )
fmt.Printf("len > %s\n", len(headers))
for i:=0;i<len(headers);i++ {
fmt.Printf("Name > %s\n", headers[i].Name)
}
select {
case <-time.After(2 * time.Second): //This works but dont stop the work2
return
}
select {
case <-time.After(2 * time.Second):
close(cs)
return
}
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/o0DYWZIlmvs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
Hi Abhi.
I believe that your logic is faulty. The timeout does take place – but it doesn’t really do what you wanted, I think.
GetWorkerValues isn’t going to send it’s info because the “range cs” can’t finish until the channel is closed. The channel is not closed until both workers are finished – timeout or not, thus it always contains the info for both workers.
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/o0DYWZIlmvs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
Hi Abhi.
I’m thinking something like this might do the job. Call monitorWorker(wg, done) as a goroutine and change it to do just the wg.Wait then send a signal on the “done” channel.
Next, start a goroutine which signals on a “timeout” channel if the timeout is exceeded.
Finally, change GetWorkerValues to be an endless loop containing a select with three cases: “<-cs” (add new value to array), “<-done” (break), and “<-timeout” (break). After the loop, send the array.
John
John Souvestre - New Orleans LA
Hi Abhi.
An afterthought: For the “done” case, add a check to clear out any “cs” values which might come in just before the “done” signal. You won’t need to worry about this in the “timeout” case.
John
John Souvestre - New Orleans LA
From: John Souvestre [mailto:Jo...@Souvestre.com]
Sent: 2017 January 08, Sun 07:27
To: 'golang-nuts'
Subject: RE: [go-nuts] Multiple goroutine timeout for waitgroup not working
Hi Abhi.
I’m thinking something like this might do the job. Call monitorWorker(wg, done) as a goroutine and change it to do just the wg.Wait then send a signal on the “done” channel.
Next, start a goroutine which signals on a “timeout” channel if the timeout is exceeded.
Finally, change GetWorkerValues to be an endless loop containing a select with three cases: “<-cs” (add new value to array), “<-done” (break), and “<-timeout” (break). After the loop, send the array.
John
John Souvestre - New Orleans LA
Sent: 2017 January 08, Sun 07:10
To: John Souvestre
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
Hi Abhi.
An afterthought: For the “done” case, add a check to clear out any “cs” values which might come in just before the “done” signal. You won’t need to worry about this in the “timeout” case.