안녕하세요. coder/websocket + Echo v5에 관해 짧게 여쭤볼게요:
Echo가 핸들러마다 전용 goroutine을 실행하니까, go readPump()를 추가하지 않고 그 goroutine에서 읽기 루프를 계속 돌려도 될까요?
func (endpoint *SocketEndpoint) ServeSocket(ctx echo.Context) error {
socket, _ := websocket.Accept(ctx.Response(), ctx.Request(), nil)
defer socket.CloseNow()
for {
_, message, readErr := socket.Read(ctx.Request().Context())
if readErr != nil { return nil }
endpoint.bus.Publish(message)
}
}
동시 쓰기는 coder/websocket 안에서 관리하니까, 별도의 writePump goroutine 없이 허브가 직접 conn.Write()를 써도 되나요? 이런 구성이 맞을까요?
영어에서 번역·원문 보기Hey folks Brief question regarding coder/websocket + Echo v5:
Given that Echo executes every handler on a goroutine of its own, can I simply keep that goroutine occupied running the read loop — without adding go readPump()?
func (endpoint *SocketEndpoint) ServeSocket(ctx echo.Context) error {
socket, _ := websocket.Accept(ctx.Response(), ctx.Request(), nil)
defer socket.CloseNow()
for {
_, message, readErr := socket.Read(ctx.Request().Context())
if readErr != nil { return nil }
endpoint.bus.Publish(message)
}
}
Since concurrent writes are managed inside coder/websocket, can the hub also use conn.Write() itself rather than having an additional writePump goroutine — would that arrangement be correct?