1
0
mirror of https://github.com/go-task/task.git synced 2025-01-08 04:04:08 +02:00

watch: isContextError is as a var func

This commit is contained in:
Andrey Nering 2017-08-05 14:04:31 -03:00
parent e78e4e6a2e
commit 26761e5445

View File

@ -18,19 +18,11 @@ var watchIgnoredDirs = []string{
func (e *Executor) watchTasks(args ...string) error { func (e *Executor) watchTasks(args ...string) error {
e.printfln("task: Started watching for tasks: %s", strings.Join(args, ", ")) e.printfln("task: Started watching for tasks: %s", strings.Join(args, ", "))
var isCtxErr = func(err error) bool {
switch err {
case context.Canceled, context.DeadlineExceeded:
return true
}
return false
}
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
for _, a := range args { for _, a := range args {
a := a a := a
go func() { go func() {
if err := e.RunTask(ctx, Call{Task: a}); err != nil && !isCtxErr(err) { if err := e.RunTask(ctx, Call{Task: a}); err != nil && !isContextError(err) {
e.println(err) e.println(err)
} }
}() }()
@ -54,7 +46,7 @@ func (e *Executor) watchTasks(args ...string) error {
for _, a := range args { for _, a := range args {
a := a a := a
go func() { go func() {
if err := e.RunTask(ctx, Call{Task: a}); err != nil && !isCtxErr(err) { if err := e.RunTask(ctx, Call{Task: a}); err != nil && !isContextError(err) {
e.println(err) e.println(err)
} }
}() }()
@ -136,3 +128,12 @@ func (e *Executor) registerWatchedFiles(w *watcher.Watcher, args []string) error
} }
return nil return nil
} }
func isContextError(err error) bool {
switch err {
case context.Canceled, context.DeadlineExceeded:
return true
default:
return false
}
}