Imagine I have a goroutine that reads from one channel and writes to another.
ch1 := make(chan int)
ch2 := make(chan int)
go func() {
for num := range ch1 {
ch2 <- num+1
}
}()
If ch2
is blocked, the goroutine will still read a value from ch1
, effectively introducing a buffer of 1 in the channel. Since I'm using channels for control flow I don't want any buffering.
How can I make a pipeline that executes in a completely lock-step fashion? Or put differently, how can I transfer a value from one channel to the next in one atomic operation?
I basically want to wait for both ch1
and ch2
to be at a rendezvous point.