Skip to content

Commit

Permalink
grpc: allocate a stream pool
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Apr 12, 2022
1 parent fb5703b commit 8705f38
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (s *Server) Subscribe(request *pb.SubscribeRequest, server pb.MarketDataSer
}
}

streamPool := map[string]types.Stream{}
for sessionName, subs := range exchangeSubscriptions {
if session, ok := s.Environ.Session(sessionName); ok {
stream := session.Exchange.NewStream()
Expand All @@ -83,10 +84,15 @@ func (s *Server) Subscribe(request *pb.SubscribeRequest, server pb.MarketDataSer
log.WithError(err).Error("grpc stream send error")
}
})
go stream.Connect(server.Context())
streamPool[sessionName] = stream
}
}

for sessionName, stream := range streamPool {
log.Infof("connecting stream %s", sessionName)
go stream.Connect(server.Context())
}

return nil
}

Expand Down

0 comments on commit 8705f38

Please sign in to comment.