From 26761e5445633874c0299f8ad876c2cf31b59df2 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 5 Aug 2017 14:04:31 -0300 Subject: [PATCH] watch: isContextError is as a var func --- watch.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/watch.go b/watch.go index 60cd8ce8..4bbf761a 100644 --- a/watch.go +++ b/watch.go @@ -18,19 +18,11 @@ var watchIgnoredDirs = []string{ func (e *Executor) watchTasks(args ...string) error { 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()) for _, a := range args { a := a 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) } }() @@ -54,7 +46,7 @@ func (e *Executor) watchTasks(args ...string) error { for _, a := range args { a := a 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) } }() @@ -136,3 +128,12 @@ func (e *Executor) registerWatchedFiles(w *watcher.Watcher, args []string) error } return nil } + +func isContextError(err error) bool { + switch err { + case context.Canceled, context.DeadlineExceeded: + return true + default: + return false + } +}