4 ms·
Please upvote parent. This is the first thing that struck my mind too. golang offers `select` for non-blocking calls. Deeply skeptical that node.js is the best
by lenkite 9y ago
Please upvote parent. This is the first thing that struck my mind too. golang offers `select` for non-blocking calls. Deeply skeptical that node.js is the best solution for a chat service. (unless the backend is serving rendered UI's)
- Thetawaves 9y agoYou 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.