converge/pkg/support/iowrappers/synchronizestreams.go
Erik Brakkee 3f3635b056 a lot of progress in setting up tests for the communication.
Wrote ChannelReadWriter that simulates a connection inmemory.
This is used by the agentserver test for testing the initialization. The
first test is already working.
2024-09-08 11:16:49 +02:00

34 lines
644 B
Go

package iowrappers
import (
"io"
"log"
)
func SynchronizeStreams(description string, stream1, stream2 io.ReadWriter) {
waitChannel := make(chan bool, 2)
go func() {
defer func() {
waitChannel <- true
}()
_, err := io.Copy(stream1, stream2)
if err != nil {
log.Printf("SynchronizeStreams: %s: error <-: %v\n", description, err)
}
}()
go func() {
defer func() {
waitChannel <- true
}()
_, err := io.Copy(stream2, stream1)
if err != nil {
log.Printf("SynchronizeStreams: %s: error ->: %v\n", description, err)
}
}()
<-waitChannel
log.Printf("SynchronizeStreams: %s: Connection closed", description)
}