AppManager: Run installation in background

Separates process into two sequential tasks: commit to config repo and
monitor release resources.

Change-Id: Ib208839dffc475b5d9c5d21758bc2a18a7f76cb7
diff --git a/core/installer/tasks/tasks.go b/core/installer/tasks/tasks.go
index 3db7042..69ddd17 100644
--- a/core/installer/tasks/tasks.go
+++ b/core/installer/tasks/tasks.go
@@ -15,6 +15,10 @@
 
 type TaskDoneListener func(err error)
 
+type Subtasks interface {
+	Tasks() []Task
+}
+
 type Task interface {
 	Title() string
 	Start()
@@ -103,11 +107,17 @@
 
 type parentTask struct {
 	leafTask
-	subtasks     []Task
+	subtasks     Subtasks
 	showChildren bool
 }
 
-func newParentTask(title string, showChildren bool, start func() error, subtasks ...Task) parentTask {
+type TaskSlice []Task
+
+func (s TaskSlice) Tasks() []Task {
+	return s
+}
+
+func newParentTask(title string, showChildren bool, start func() error, subtasks Subtasks) parentTask {
 	return parentTask{
 		leafTask:     newLeafTask(title, start),
 		subtasks:     subtasks,
@@ -117,17 +127,13 @@
 
 func (t *parentTask) Subtasks() []Task {
 	if t.showChildren {
-		return t.subtasks
+		return t.subtasks.Tasks()
 	} else {
 		return make([]Task, 0)
 	}
 }
 
-type sequentialParentTask struct {
-	parentTask
-}
-
-func newSequentialParentTask(title string, showChildren bool, subtasks ...Task) *sequentialParentTask {
+func newSequentialParentTask(title string, showChildren bool, subtasks ...Task) *parentTask {
 	start := func() error {
 		errCh := make(chan error)
 		for i := range subtasks[:len(subtasks)-1] {
@@ -146,16 +152,11 @@
 		go subtasks[0].Start()
 		return <-errCh
 	}
-	return &sequentialParentTask{
-		parentTask: newParentTask(title, showChildren, start, subtasks...),
-	}
+	t := newParentTask(title, showChildren, start, TaskSlice(subtasks))
+	return &t
 }
 
-type concurrentParentTask struct {
-	parentTask
-}
-
-func newConcurrentParentTask(title string, showChildren bool, subtasks ...Task) *concurrentParentTask {
+func newConcurrentParentTask(title string, showChildren bool, subtasks ...Task) *parentTask {
 	start := func() error {
 		errCh := make(chan error)
 		for i := range subtasks {
@@ -177,7 +178,6 @@
 		}
 		return nil
 	}
-	return &concurrentParentTask{
-		parentTask: newParentTask(title, showChildren, start, subtasks...),
-	}
+	t := newParentTask(title, showChildren, start, TaskSlice(subtasks))
+	return &t
 }