MCPcopy
hub / github.com/coder/websocket / goDiscardLoop

Method goDiscardLoop

conn_test.go:539–559  ·  view source on GitHub ↗
(c *websocket.Conn)

Source from the content-addressed store, hash-verified

537}
538
539func (tt *connTest) goDiscardLoop(c *websocket.Conn) {
540 ctx, cancel := context.WithCancel(tt.ctx)
541
542 discardLoopErr := xsync.Go(func() error {
543 defer c.Close(websocket.StatusInternalError, "")
544
545 for {
546 _, _, err := c.Read(ctx)
547 if err != nil {
548 return assertCloseStatus(websocket.StatusNormalClosure, err)
549 }
550 }
551 })
552 tt.t.Cleanup(func() {
553 cancel()
554 err := <-discardLoopErr
555 if err != nil {
556 tt.t.Errorf("discard loop error: %v", err)
557 }
558 })
559}
560
561func BenchmarkConn(b *testing.B) {
562 benchCases := []struct {

Callers 1

TestConnFunction · 0.80

Calls 4

GoFunction · 0.92
assertCloseStatusFunction · 0.70
CloseMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected