If you cannot change the signature of your execute method, you can write a convenience method to make it easier to create a callback:
def async(f: Response => Response)(handler: Throwable => Unit) = new AsyncCompletionHandler[Response]() { @throws(classOf[Exception]) override def onCompleted(response: Response): Response = f(response) override def onThrowable(t: Throwable) = handler(t) }
Then you can write your code, for example
asyncHttpClient.prepareGet("http://www.ning.com/ ").execute(async { response => // do something with response } { caught => // handle failure }
source share