MCPcopy Create free account
hub / github.com/encodeous/nylon / mainLoop

Method mainLoop

core/nylon.go:275–310  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

273}
274
275func (n *Nylon) mainLoop() error {
276 n.Log.Debug("started main loop")
277 for {
278 select {
279 case fun := <-n.DispatchChannel:
280 if fun == nil {
281 goto endLoop
282 }
283 //n.Log.Debug("start")
284 start := time.Now()
285 err := fun()
286 if err != nil {
287 n.Log.Error("error occurred during dispatch: ", "error", err)
288 n.Cancel(err)
289 }
290 elapsed := time.Since(start)
291 perf.DispatchLatency.Add(float64(elapsed.Microseconds()))
292 if elapsed > time.Millisecond*4 {
293 n.Log.Warn("dispatch took a long time!", "fun", runtime.FuncForPC(reflect.ValueOf(fun).Pointer()).Name(), "elapsed", elapsed, "len", len(n.DispatchChannel))
294 }
295 //n.Log.Debug("done", "elapsed", elapsed)
296 case <-n.Context.Done():
297 goto endLoop
298 }
299 }
300endLoop:
301 n.Log.Info("stopped main loop", "reason", context.Cause(n.Context).Error())
302 n.Stop()
303 n.Log.Info("cleaning up modules")
304 err := n.Cleanup()
305 if err != nil {
306 n.Log.Error("error occurred during Stop: ", "error", err)
307 }
308 n.Log.Info("stopped")
309 return nil
310}
311
312func (n *Nylon) Cleanup() error {
313 n.PingBuf.Stop()

Callers 1

StartMethod · 0.95

Calls 5

StopMethod · 0.95
CleanupMethod · 0.95
NameMethod · 0.65
ErrorMethod · 0.45
CancelMethod · 0.45

Tested by

no test coverage detected