title: How to rate limit function call in a loop in Scala
body: <p>
  The following code do a bunch of calls to an external API. This API <strong>does not allow more than 3 queries per second</strong>. <code>syncCallToApi</code> is a function provided by the api client library that do a synchronous request and returns the result.</p>
  
  <p>What is the best way in Scala to concurrently call <code>callToApi</code> no more than 3 times per seconds while keeping the following  semantics:</p>
  
  <pre class="lang-scala prettyprint-override"><code>val ids = Seq(12980,2932,3441,42334,980,32,4531,7234)
  val results: Seq[Item] = ids.map(id =&gt; syncCallToApi(id)) 
  println(results)
  </code></pre>