I used the TimeoutScheduler introduced in Scala Futures - built-in timeout? .
However, now my program does not end as before without TimeoutScheduler .
I have two Future s: res1 and res2 . Both with a timeout of 15 seconds. In the end, I execute the Future sequence to shut down the HTTP artist normally in the onComplete callback. Without using withTimeout program ends immediately after http.shutdown . But using withTimeout not. What for? There must be some further future ...
import java.net.URI import scala.util.{ Try, Failure, Success } import dispatch._ import org.json4s._ import org.json4s.native.JsonMethods._ import com.typesafe.scalalogging.slf4j.Logging object Main extends App with Logging { import scala.concurrent.ExecutionContext.Implicits.global val http = Http val github = host("api.github.com").secure import timeout._ import scala.concurrent.duration._ import scala.language.postfixOps import scala.collection.JavaConverters._ val req: dispatch.Req = github / "users" / "defunkt" val res1 = http(req > dispatch.as.Response(_.getHeaders().get("Server").asScala)) withTimeout (15 seconds) recover { case x => logger.debug("Error1: " + x.toString) Nil } val res2 = http(req > dispatch.as.Response(_.getHeaders().get("Vary").asScala)) withTimeout (15 seconds) recover { case x => logger.debug("Error2: " + x.toString) Nil } Future.sequence(res1 :: res2 :: Nil) onComplete { case _ => http.shutdown()
Any suggestions are welcome, Best, / nm
scala future scala-dispatch
Normen MΓΌller Feb 24 '14 at 9:11 2014-02-24 09:11
source share