Skip to content

Commit ebba03b

Browse files
committed
pkg/loop: wait from chain family
1 parent 8fd3a49 commit ebba03b

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

pkg/loop/internal/goplugin/plugin_service.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,17 @@ func (s *PluginService[P, S]) WaitCtx(ctx context.Context) error {
257257
case <-s.serviceCh:
258258
return nil
259259
case <-s.stopCh:
260-
return fmt.Errorf("service was stoped while waiting: %w", context.Canceled)
260+
return fmt.Errorf("service was stopped while waiting: %w", context.Canceled)
261+
}
262+
}
263+
264+
// Wait waits for the service to start up until it receives the stop signal.
265+
func (s *PluginService[P, S]) Wait() error {
266+
select {
267+
case <-s.serviceCh:
268+
return nil
269+
case <-s.stopCh:
270+
return fmt.Errorf("service was stopped while waiting: %w", context.Canceled)
261271
}
262272
}
263273

pkg/loop/relayer_service.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ func NewRelayerService(lggr logger.Logger, grpcOpts GRPCOpts, cmd func() *exec.C
4343
}
4444

4545
func (r *RelayerService) EVM() (types.EVMService, error) {
46+
if err := r.Wait(); err != nil {
47+
return nil, err
48+
}
4649
return r.Service.EVM()
4750
}
4851

4952
func (r *RelayerService) TON() (types.TONService, error) {
53+
if err := r.Wait(); err != nil {
54+
return nil, err
55+
}
5056
return r.Service.TON()
5157
}
5258

@@ -107,6 +113,9 @@ func (r *RelayerService) GetChainStatus(ctx context.Context) (types.ChainStatus,
107113
}
108114

109115
func (r *RelayerService) GetChainInfo(ctx context.Context) (types.ChainInfo, error) {
116+
if err := r.WaitCtx(ctx); err != nil {
117+
return types.ChainInfo{}, err
118+
}
110119
return r.Service.GetChainInfo(ctx)
111120
}
112121

0 commit comments

Comments
 (0)