修改 命名

This commit is contained in:
dengsgo 2018-12-30 15:14:14 +08:00
parent 755a7e8c07
commit afcceb7753
2 changed files with 10 additions and 10 deletions

View File

@ -24,7 +24,7 @@ var (
watcher *fsnotify.Watcher watcher *fsnotify.Watcher
tasker *Tasker taskMan *TaskMan
) )
type changeFile struct { type changeFile struct {
@ -61,7 +61,7 @@ func eventDispatcher(event fsnotify.Event) {
case fsnotify.Create: case fsnotify.Create:
case fsnotify.Write: case fsnotify.Write:
log.Println("event write : ", event.Name) log.Println("event write : ", event.Name)
tasker.Put(&changeFile{ taskMan.Put(&changeFile{
Name: relativePath(projectFolder, event.Name), Name: relativePath(projectFolder, event.Name),
Changed: time.Now().UnixNano(), Changed: time.Now().UnixNano(),
Ext: ext, Ext: ext,
@ -130,7 +130,7 @@ func initWatcher() {
defer watcher.Close() defer watcher.Close()
done := make(chan bool) done := make(chan bool)
tasker = newTasker(2000) taskMan = newTaskMan(2000)
go func() { go func() {
for { for {
select { select {
@ -177,7 +177,7 @@ func parseArgs() {
return return
case "exec": case "exec":
parseConfig() parseConfig()
newTasker(0).run(new(changeFile)) newTaskMan(0).run(new(changeFile))
return return
case "version": case "version":
fallthrough fallthrough

View File

@ -10,7 +10,7 @@ import (
"time" "time"
) )
type Tasker struct { type TaskMan struct {
lastTaskId int64 lastTaskId int64
delay int delay int
cmd *exec.Cmd cmd *exec.Cmd
@ -18,13 +18,13 @@ type Tasker struct {
runLock sync.Mutex runLock sync.Mutex
} }
func newTasker(delay int) *Tasker { func newTaskMan(delay int) *TaskMan {
return &Tasker{ return &TaskMan{
delay: delay, delay: delay,
} }
} }
func (t *Tasker) Put(cf *changeFile) { func (t *TaskMan) Put(cf *changeFile) {
if t.delay < 1 { if t.delay < 1 {
t.preRun(cf) t.preRun(cf)
return return
@ -42,7 +42,7 @@ func (t *Tasker) Put(cf *changeFile) {
}() }()
} }
func (t *Tasker) preRun(cf *changeFile) { func (t *TaskMan) preRun(cf *changeFile) {
if t.cmd != nil { if t.cmd != nil {
err := t.cmd.Process.Kill() err := t.cmd.Process.Kill()
if err != nil { if err != nil {
@ -53,7 +53,7 @@ func (t *Tasker) preRun(cf *changeFile) {
go t.run(cf) go t.run(cf)
} }
func (t *Tasker) run(cf *changeFile) { func (t *TaskMan) run(cf *changeFile) {
t.runLock.Lock() t.runLock.Lock()
defer t.runLock.Unlock() defer t.runLock.Unlock()
for i := 0; i < len(cfg.Command.Exec); i++ { for i := 0; i < len(cfg.Command.Exec); i++ {