title: Scala Invoking Multiple futures - Consuming Queue when available
body: <p>I have a use case where I will make a call to an API which will return a list of ID's that I need to make a second API call.I am trying to use Scala Futures here, but seems stuck.</p>
  <p>I have a scaled down example where i will add repose of first API to inpQueue and then iterate the inpQueue for making second APi call.
  I need to start making the second API call as soon as data is available in the inpQueue. I tried to use Stream.continually(inpQueue), but it seems not working.</p>
  <pre class="lang-scala prettyprint-override"><code>object DependentFutures {
  
    val datasets: immutable.Seq[(Int, String)] = 
  Seq((1,&quot;2X6barD&quot;), (2,&quot;3d9vCgW&quot;), (3,&quot;2M02Xz0&quot;), (4,&quot;2XOu2uL&quot;), (5,&quot;2AfBWF0&quot;)).toList
  
  
    var inpQueue  =  new ArrayBlockingQueue[Future[ (Int, String)]](1000)
  
    def addToQueue(params: (Int, String))(implicit ec: ExecutionContext):Future[ (Int, String)] = Future {
      val d = Future {(params._1 + 1, params._2)}
      inpQueue.put(d)
  
      println(new java.sql.Timestamp(System.currentTimeMillis())+&quot; -&gt; &quot;+params._1 )
      (params._1+1, params._2)
    }
  
    def main(args: Array[String]): Unit = {
  
  
      val executor: ExecutorService = Executors.newFixedThreadPool(1)
      implicit val executionContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(executor)
  
  
  
      val q1 = Future.traverse(datasets)(addToQueue).andThen {
        case result =&gt;
          println(&quot;* processing is over, shutting down the executor&quot;)
          executionContext.shutdown()
      }
  
      val x = Future.sequence(in)
      Await.result(inpQueue, Duration(10, &quot;seconds&quot;)))(implicit ec: ExecutionContext)
    }
  }
  </code></pre>