Skip to content

Commit

Permalink
sse api: skip sending to subscriber if queue is full
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Jun 24, 2024
1 parent 5567b87 commit fb9da19
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func New(cfg *HTTPServerConfig) (srv *Server) {
mux := chi.NewRouter()

mux.With(srv.httpLogger).Get("/sse/transactions", srv.handleTxSSE)
// mux.With(srv.httpLogger).Get("/sse/dummyTx", srv.handleDummyTx)

if cfg.EnablePprof {
srv.log.Info("pprof API enabled")
Expand Down Expand Up @@ -117,8 +116,12 @@ func (s *Server) SendTx(ctx context.Context, tx *common.TxIn) error {
return err
}

// Send tx to all subscribers (only if channel is not full)
for _, sub := range s.sseConnectionMap {
sub.txC <- txRLP
select {
case sub.txC <- txRLP:
default:
}
}

return nil
Expand Down

0 comments on commit fb9da19

Please sign in to comment.