This page is no longer maintained — Please continue to the home page at

Alternative to count down latch

No replies
John L. Cheng
Joined: 2011-07-30,
User offline. Last seen 42 years 45 weeks ago.

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

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) {
override def failed(exception: Exception) {
override def cancelled() {

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