optimize for small number of tasks

pull/1162/merge
Darien Raymond 2018-06-07 06:38:45 +02:00
parent cbca610cce
commit 3620ebfc11
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 9 additions and 0 deletions

View File

@ -56,6 +56,15 @@ func Parallel(tasks ...Task) ExecutionOption {
func Sequential(tasks ...Task) ExecutionOption { func Sequential(tasks ...Task) ExecutionOption {
return func(c *executionContext) { 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 { c.tasks = append(c.tasks, func() error {
return execute(tasks...) return execute(tasks...)
}) })