title: How to coordinate a list of Completable executions with RxJava?
body: <p>I have a list of <code>BlockingTasks</code> that I want to run sequentially:</p>
  
  <pre><code>class BlockingTaskManager {
      val tasks = mutableListOf&lt;BlockingTask&gt;()
  
      fun run () : Completable {
          /* What can I put here in order to run
             all tasks and return a completable according with the
             requirements described below? */
      }
  }
  
  interface BlockingTask {
  
      fun run () : Completable
  
      fun getDescription(): String
  
      fun blockPipe(): Boolean
  }
  </code></pre>
  
  <h2>Requirements</h2>
  
  <ul>
  <li>If any <code>Completable</code> in the pipe finishes with error, the whole execution should stop.;</li>
  <li>When a <code>Completable</code> returned by <code>run()</code> finishes, either with error or success, a log containing the timestamp and the String returned by <code>getDescription()</code> should be issued;</li>
  </ul>
  
  <hr>
  
  <p>I thought about using <code>Completable.concat { tasks }</code>, but I don't see how I can call <code>currentIterationTask.run()</code> and how to fail the pipe if <code>run()</code> results on error, as well as logging <code>currentInterationTask.getDescription()</code>.</p>
  
  <p>Another idea was using <code>andThen()</code>, but I'm not sure if it will work as needed:</p>
  
  <pre><code>    tasks.forEachIndexed {
          idx, task -&gt;
          var isBroken = false
          task.run()
                  .doOnComplete {
                      logTaskCompletedSuccessfully(task)
                  }
                  .doOnError {
                      error -&gt;
                      logTaskFailed(task, error)
                      isBroken = task.blockPipe()
                  }
                  .andThen {
                      if (!isBroken &amp;&amp; idx &lt; tasks.size) {
                          tasks[idx+1]
                      }
                  }
      }
  </code></pre>