mirror of
https://github.com/go-task/task.git
synced 2025-01-06 03:53:54 +02:00
watch: isContextError is as a var func
This commit is contained in:
parent
e78e4e6a2e
commit
26761e5445
21
watch.go
21
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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user