Yes you can because function are just code and the code you have mentioned works fine as what you have mentioned that if you remove close then for loop will run forever as it might not able to find out whether the channel still have something to send and wait as channels sends 2 thing value and ok where okay tells whether the channels opened or close if you use close that ok becomes false and for loop terminates
--
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.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/4a665d05-d769-4249-a6df-4e3de0589d1an%40googlegroups.com.
--
--
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.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/8b343e2a-ab29-4c33-8f3f-beb5b61ae09dn%40googlegroups.com.
See when we create w0 goroutine then a new thread will be generated so now we have 2 thread one main another w0 now from w0 we can w which will run of w0 thread and run sequentially so program will not execute in w0 till w not returned then ur channel close now at the time u have executed the w the function w keeps sending data to channel. now on that time main goroutine will wait untill the channel closes and which eventually going to close after close function after w returns to w0. So its the complete flow
--
w(t,c) { if t!=nil { w(t.left,c) ; c<-t.elem ; w(t.right,c) }}w0(t,c) { w(t,c); close(c); }main(){go w0(t,c)for e := range c {}}
--
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.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/aibi2KAdNzkks/Bd%40basil.wdw.