Search code examples
asynchronousakkasprayspray-client

Accessing spray request from spray response


I'm calling this function every 50 ms :

def send() = {
    val myData = generateRandomData()
    val response = pipeline(Post("http://slow-website.com/send", myData))
    response onComplete {
      case Success(r) => ? how to access myData  ?

      case Failure(error) => print(error.getMessage)
    }
}

I would like to know what data was sent in my successfull request.
How can I achieve this?


Solution

  • Just refer to myData.

    What happens behind the scenes is that the Scala compiler creates a closure for the onComplete handler argument that captures the reference to myData so that you can use it.