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?