mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 01:01:56 +00:00
grpc: allocate a stream pool
This commit is contained in:
parent
fb5703bf13
commit
8705f38220
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user