Track a small async-style workflow through stages.

Pipeline State

PipelineState.scala
object Main {
  def main(args: Array[String]): Unit = {
    val retries = 
    var stage = "queued"
    var attempts = 0

    stage = "started"
    attempts = attempts + 1

    if (retries > 0) {
      attempts = attempts + retries
    }

    val success = attempts <= 2
    if (success) {
      stage = "complete"
    } else {
      stage = "retry-later"
    }

    println("attempts=" + attempts)
    println("stage=" + stage)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val retries = 
    var stage = "queued"
    var attempts = 0

    stage = "started"
    attempts = attempts + 1

    if (retries > 0) {
      attempts = attempts + retries
    }

    val success = attempts <= 2
    if (success) {
      stage = "complete"
    } else {
      stage = "retry-later"
    }

    println("attempts=" + attempts)
    println("stage=" + stage)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val retries = 
    var stage = "queued"
    var attempts = 0

    stage = "started"
    attempts = attempts + 1

    if (retries > 0) {
      attempts = attempts + retries
    }

    val success = attempts <= 2
    if (success) {
      stage = "complete"
    } else {
      stage = "retry-later"
    }

    println("attempts=" + attempts)
    println("stage=" + stage)
  }
}
pipeline-state A larger async workflow is often a series of state changes: queued, started, retried, and complete or delayed. Local variables make those stages replayable.