[Solved] How can I overlap goroutines?


If you need such sequencing, you might reevaluate your need to use goroutines. However, the way you described the solution is correct:

go first() {
  for {
    <-ch1
    // do stuff
    ch2<-struct{}{}
  } 
}()

go second() {
  for {
    <-ch2
    // do stuff
    ch3<-struct{}{}
  } 
}()

go third() {
  for {
    <-ch3
    // do stuff
    ch1<-struct{}{}
  } 
}()

However, this is a circular setup, and you have to start the first one outside this structure:

go first() {...}()
go second() {...}()
go third() {...} ()

// Start the first one
ch1<-struct{}{}

2

solved How can I overlap goroutines?