ws-examples
ws-examples copied to clipboard
Why do we use netpoll event descriptor instead of just a reader goroutine?
I'm trying to understand the example, specifically why do we need to create a netpoll even descriptor for the purpose of reading messages from the connection?
Comparing to most other websocket library examples, I usually see just a dedicated goroutine for reading messages, and usually another separate goroutine for writing messages. Why the seemingly unnecessary complication here?
Would creating a separate reader goroutine for every connection achieve the same thing?
// Create netpoll event descriptor for conn.
// We want to handle only read events of it.
desc := netpoll.Must(netpoll.HandleRead(conn))