瀏覽代碼

optimize for small number of tasks

Darien Raymond 7 年之前
父節點
當前提交
3620ebfc11
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      common/task/task.go

+ 9 - 0
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...)
 		})