Endless loop and never return
()
| 395 | |
| 396 | // Endless loop and never return |
| 397 | func (e *Engine) start() { |
| 398 | if e.config.Proxy.Enabled { |
| 399 | go e.proxy.Run() |
| 400 | e.mainLog("Proxy server listening on http://localhost%s", e.proxy.server.Addr) |
| 401 | } |
| 402 | |
| 403 | e.running.Store(true) |
| 404 | firstRunCh := make(chan bool, 1) |
| 405 | firstRunCh <- true |
| 406 | |
| 407 | for { |
| 408 | var filename string |
| 409 | |
| 410 | select { |
| 411 | case <-e.exitCh: |
| 412 | e.mainDebug("exit in start") |
| 413 | return |
| 414 | case filename = <-e.eventCh: |
| 415 | if !e.isIncludeExt(filename) && !e.checkIncludeFile(filename) { |
| 416 | continue |
| 417 | } |
| 418 | if e.config.Build.ExcludeUnchanged { |
| 419 | if !e.isModified(filename) { |
| 420 | e.mainLog("skipping %s because contents unchanged", e.config.rel(filename)) |
| 421 | continue |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | // cannot set buildDelay to 0, because when the write multiple events received in short time |
| 426 | // it will start Multiple buildRuns: https://github.com/air-verse/air/issues/473 |
| 427 | time.Sleep(e.config.buildDelay()) |
| 428 | e.flushEvents() |
| 429 | |
| 430 | if e.config.Screen.ClearOnRebuild { |
| 431 | if e.config.Screen.KeepScroll { |
| 432 | // https://stackoverflow.com/questions/22891644/how-can-i-clear-the-terminal-screen-in-go |
| 433 | fmt.Print("\033[2J") |
| 434 | } else { |
| 435 | // https://stackoverflow.com/questions/5367068/clear-a-terminal-screen-for-real/5367075#5367075 |
| 436 | fmt.Print("\033c") |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | e.mainLog("%s has changed", e.config.rel(filename)) |
| 441 | case <-firstRunCh: |
| 442 | // go down |
| 443 | } |
| 444 | |
| 445 | // Stop any currently running build by closing its stop channel |
| 446 | select { |
| 447 | case oldStopCh := <-e.buildRunCh: |
| 448 | // Close the old build's stop channel to signal it to stop |
| 449 | close(oldStopCh) |
| 450 | default: |
| 451 | // No build is currently running |
| 452 | } |
| 453 | |
| 454 | go e.buildRun() |
no test coverage detected