How to achieve an akka scheduler inside a loop for the timely ouput
<p>I got a functionality to do something over a timer inside a loop. So I thought of using akka scheduler to achieve it.
Here is my sample code (written inside an akka actor) :</p>

<pre><code>class TestActor extends Actor {

  override def receive: Receive = {
    case num: Int =&gt; println(num)
    case Tick =&gt; loopAndPrint
  }

  def loopAndPrint = {
    val list = List(1, 100, 5, 23)
    list.map { l =&gt;
      context.system.scheduler.scheduleOnce(Duration.create(30, TimeUnit.SECONDS), self, l)
    }
  }

}
</code></pre>

<p>I was expecting that the println will be called every 30 seconds until the end of the list. But it started after 30 seconds and ended up printing all the list items at a time.</p>

<p>How can I achieve this to print the list items every 30 seconds after the start ?</p>

<p>Thanks in advance.</p>