0

I am currently making an API call and I am blocking for 1 second waiting for the result:

 val status = Await.ready(Http(address OK as.String), 1 second)
 status onComplete

I would like to do the same but without blocking.

So I tried something like this, where I am creating another future, putting that thread to sleep for a second and then collecting the result.

  val status: Future[String] = Http(address OK as.String)
  val waitForStatus: Future[String] = {
    Thread.sleep(1000)
    status.collect
  }

  val receiver = sender
  status onComplete {

However, this doesn't work:

 polymorphic expression cannot be instantiated to expected type;
[error]  found   : [S](pf: PartialFunction[String,S])(implicit executor: scala.concurrent.ExecutionContext)scala.concurrent.Future[S]
[error]  required: scala.concurrent.Future[String]
[error]         status.collect

And I'm not sure if it's blocking or not.

So what's a non-blocking way of waiting for a Future for 1 second?

bsky
  • 19,326
  • 49
  • 155
  • 270
  • 3
    I think this is what you are looking for http://stackoverflow.com/questions/16304471/scala-futures-built-in-timeout – Tyth Dec 19 '16 at 11:31
  • Could you explain what you want to achieve? `onComplete` is a callback that will execute when the Future is ready. There's no need to `Await` for it. – maasg Dec 19 '16 at 11:43

0 Answers0