File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed
internal/sms-gateway/modules/sse Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -134,11 +134,14 @@ func (s *Service) handleStream(deviceID string, w *bufio.Writer) {
134134 conn := s .registerConnection (deviceID )
135135 defer s .removeConnection (deviceID , conn .id )
136136
137+ var tickerChan <- chan time.Time
138+
137139 // Conditionally create ticker
138- var ticker * time.Ticker
139140 if s .config .keepAlivePeriod > 0 {
140- ticker = time .NewTicker (s .config .keepAlivePeriod )
141+ ticker : = time .NewTicker (s .config .keepAlivePeriod )
141142 defer ticker .Stop ()
143+
144+ tickerChan = ticker .C
142145 }
143146
144147 for {
@@ -154,13 +157,7 @@ func (s *Service) handleStream(deviceID string, w *bufio.Writer) {
154157 }
155158 })
156159 // Conditionally handle ticker events
157- case <- func () <- chan time.Time {
158- if ticker != nil {
159- return ticker .C
160- }
161- // Return nil channel that never fires when disabled
162- return make (chan time.Time )
163- }():
160+ case <- tickerChan :
164161 if err := s .writeToStream (w , ":keepalive" ); err != nil {
165162 s .logger .Warn ("Failed to write keepalive" ,
166163 zap .String ("device_id" , deviceID ),
You can’t perform that action at this time.
0 commit comments