Alternative to count down latch

Just a curiosity, is there a more Scalatastic/Scalariffic/Scala-like
way of doing this:

http://hc.apache.org/httpcomponents-asyncclient-dev/examples.html

http://hc.apache.org/httpcomponents-asyncclient-dev/httpasyncclient/exam...

In essence, waiting for a set of callbacks to get invoked/events to be
fired. The CountDownLatch class appears to be optimal in the case of
sending a batch of requests then waiting for the batch to complete.

By the way, similar code using the HttpAsyncClient in Scala looks
something like this:

val latch = new CountDownLatch(docIds.length)
docIds.foreach { docId =>
val put = new HttpPut(dbUrl + "/" + docId + "?batch=ok")
put.setEntity(new StringEntity(doc))
asyncHttpClient.execute(put, new FutureCallback[HttpResponse]() {
override def completed(response: HttpResponse) {
EntityUtils.consume(response.getEntity())
latch.countDown()
}
override def failed(exception: Exception) {
latch.countDown()
}
override def cancelled() {
latch.countDown()
}
})
}
latch.await()

Copyright © 2013 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland