From b880d5b1f5e6ce8a3068b65e73bb5f6865dfe987 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 15 May 2024 10:52:26 +0100 Subject: [PATCH] close ticker --- go/common/subscription/utils.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/go/common/subscription/utils.go b/go/common/subscription/utils.go index fe50c09cdc..4179cf476c 100644 --- a/go/common/subscription/utils.go +++ b/go/common/subscription/utils.go @@ -17,10 +17,12 @@ import ( func ForwardFromChannels[R any](inputChannels []chan R, onMessage func(R) error, onBackendDisconnect func(), backendDisconnected *atomic.Bool, stopped *atomic.Bool, timeoutInterval time.Duration, logger gethlog.Logger) { inputCases := make([]reflect.SelectCase, len(inputChannels)+1) + cleanupTicker := time.NewTicker(2 * time.Second) + defer cleanupTicker.Stop() // create a ticker to handle cleanup, check the "stopped" flag and exit the goroutine inputCases[0] = reflect.SelectCase{ Dir: reflect.SelectRecv, - Chan: reflect.ValueOf(time.NewTicker(2 * time.Second).C), + Chan: reflect.ValueOf(cleanupTicker.C), } // create a select "case" for each input channel