Skip to content

Commit

Permalink
Rewrite func iterator to range loop in p2p/starknet.streamHandler (#2106
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kirugan authored Sep 2, 2024
1 parent 77b0d60 commit ef162c3
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions p2p/starknet/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,17 @@ func streamHandler[ReqT proto.Message](ctx context.Context, wg *sync.WaitGroup,
return
}

// todo add write timeout
responseIterator(func(msg proto.Message) bool {
for msg := range responseIterator {
if ctx.Err() != nil {
return false
break
}

// todo add write timeout
if _, err := protodelim.MarshalTo(stream, msg); err != nil { // todo: figure out if we need buffered io here
log.Debugw("Error writing response", "peer", stream.ID(), "protocol", stream.Protocol(), "err", err)
return false
break
}

return true
})
}
}

func (h *Handler) HeadersHandler(stream network.Stream) {
Expand Down

0 comments on commit ef162c3

Please sign in to comment.