From 3620ebfc1114e967b3a12838718baab8e2d261a1 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 7 Jun 2018 06:38:45 +0200 Subject: [PATCH] optimize for small number of tasks --- common/task/task.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/task/task.go b/common/task/task.go index 72f327ef2..e1640eac7 100644 --- a/common/task/task.go +++ b/common/task/task.go @@ -56,6 +56,15 @@ func Parallel(tasks ...Task) ExecutionOption { func Sequential(tasks ...Task) ExecutionOption { return func(c *executionContext) { + if len(tasks) == 0 { + return + } + + if len(tasks) == 1 { + c.tasks = append(c.tasks, tasks[0]) + return + } + c.tasks = append(c.tasks, func() error { return execute(tasks...) })