ws-examples icon indicating copy to clipboard operation
ws-examples copied to clipboard

Why do we use netpoll event descriptor instead of just a reader goroutine?

Open ccnlui opened this issue 3 years ago • 0 comments

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))

ccnlui avatar Mar 16 '22 21:03 ccnlui