代码拉取完成,页面将自动刷新
package runner
import (
"fmt"
"os"
"runtime"
"strings"
"time"
)
var (
startChannel chan string
stopChannel chan bool
mainLog logFunc
watcherLog logFunc
runnerLog logFunc
buildLog logFunc
appLog logFunc
)
func flushEvents() {
for {
select {
case eventName := <-startChannel:
mainLog("receiving event %s", eventName)
default:
return
}
}
}
func start() {
loopIndex := 0
buildDelay := buildDelay()
started := false
go func() {
for {
loopIndex++
mainLog("Waiting (loop %d)...", loopIndex)
eventName := <-startChannel
mainLog("receiving first event %s", eventName)
mainLog("sleeping for %d milliseconds", buildDelay)
time.Sleep(buildDelay * time.Millisecond)
mainLog("flushing events")
flushEvents()
mainLog("Started! (%d Goroutines)", runtime.NumGoroutine())
err := removeBuildErrorsLog()
if err != nil {
mainLog(err.Error())
}
buildFailed := false
if shouldRebuild(eventName) {
errorMessage, ok := build()
if !ok {
buildFailed = true
mainLog("Build Failed: \n %s", errorMessage)
if !started {
os.Exit(1)
}
createBuildErrorsLog(errorMessage)
}
}
if !buildFailed {
if started {
stopChannel <- true
}
run()
}
started = true
mainLog(strings.Repeat("-", 20))
}
}()
}
func init() {
startChannel = make(chan string, 1000)
stopChannel = make(chan bool)
}
func initLogFuncs() {
mainLog = newLogFunc("main")
watcherLog = newLogFunc("watcher")
runnerLog = newLogFunc("runner")
buildLog = newLogFunc("build")
appLog = newLogFunc("app")
}
func setEnvVars() {
os.Setenv("DEV_RUNNER", "1")
wd, err := os.Getwd()
if err == nil {
os.Setenv("RUNNER_WD", wd)
}
for k, v := range settings {
key := strings.ToUpper(fmt.Sprintf("%s%s", envSettingsPrefix, k))
os.Setenv(key, v)
}
}
// Watches for file changes in the root directory.
// After each file system event it builds and (re)starts the application.
func Start() {
initLimit()
initSettings()
initLogFuncs()
initFolders()
setEnvVars()
watch()
start()
startChannel <- "/"
<-make(chan int)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。