[#72] Shutdown inner ring app if RPC node has been terminated

Adopt error channel from Listener interface.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-13 18:40:35 +03:00 committed by Alex Vanin
parent ccbb9ce6ab
commit dd48666357
2 changed files with 27 additions and 6 deletions

View file

@ -75,7 +75,7 @@ const (
)
// Start runs all event providers.
func (s *Server) Start(ctx context.Context) error {
func (s *Server) Start(ctx context.Context, intError chan<- error) error {
err := s.initConfigFromBlockchain()
if err != nil {
return err
@ -83,8 +83,23 @@ func (s *Server) Start(ctx context.Context) error {
s.localTimers.Start(ctx) // local timers start ticking
go s.morphListener.Listen(ctx) // listen for neo:morph events
go s.mainnetListener.Listen(ctx) // listen for neo:mainnet events
morphErr := make(chan error)
mainnnetErr := make(chan error)
// anonymous function to multiplex error channels
go func() {
select {
case <-ctx.Done():
return
case err := <-morphErr:
intError <- errors.Wrap(err, "sidechain")
case err := <-mainnnetErr:
intError <- errors.Wrap(err, "mainnet")
}
}()
go s.morphListener.ListenWithError(ctx, morphErr) // listen for neo:morph events
go s.mainnetListener.ListenWithError(ctx, mainnnetErr) // listen for neo:mainnet events
return nil
}