3 ms·
You generally need one thread to read for incoming messages, typical: for { select { case <-finish: done <- true return
by Thetawaves 9y ago
You generally need one thread to read for incoming messages, typical:
for {
select {
case <-finish:
done <- true
return
default:
// read from the socket
}
}
You need another thread to listen for messages on a channel and send them out the socket
typical:
for {
select {
case <-finish:
done <- true
return
case msg <- msg_out:
// write msg to socket
}
}
- tankenmate 9y agoInstead of? for { select { case <-finish: done <- true return case msg <- msg_out: // write handling case <-pubsub: // handle oob controls default: // read handling } }
- Thetawaves 9y agoYou wont be able to write messages while blocked on the read in this scenario.