1

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?

Martin Magakian
  • 3,746
  • 5
  • 37
  • 53

1 Answers1

3

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.

jrudolph
  • 8,307
  • 4
  • 32
  • 50