dispatch.Http.shutdown()
如果有独立的 Http调用n
,例如:
import com.typesafe.scalalogging.slf4j.Logging
import org.json4s._
import org.json4s.native.JsonMethods._
import scala.util.{ Failure, Success }
object Main extends App with Logging {
logger.debug("github.cli")
// GET /users/defunkt: `curl https://api.github.com/users/defunkt`
val host: dispatch.Req = dispatch.host("api.github.com").secure
val request: dispatch.Req = host / "users" / "defunkt"
logger.debug(s"Request URL: ${request.url}")
import dispatch.Defaults.executor
dispatch.Http(request > dispatch.as.Response(_.getHeaders())) onComplete {
case Success(h) => logger.debug(h.toString())
case Failure(e) => logger.debug(s"Error: $e")
}
dispatch.Http(request OK dispatch.as.json4s.Json) onComplete {
case Success(j) => logger.debug(j.toString())
case Failure(e) => logger.debug(s"Error: $e")
}
//dispatch.Http.shutdown() // <<<<< ?????
}
谢谢,/纳米
编辑:这可能是一种选择,比如说,这是一种“正确”的方式吗?
val headers = dispatch.Http(request > dispatch.as.Response(_.getHeaders()))
val user = dispatch.Http(request OK dispatch.as.json4s.Json)
val all = dispatch.Future.sequence(headers :: user :: Nil)
headers onComplete {
case Success(h) => logger.debug(s"Header: ${h.toString()}")
case Failure(e) => logger.debug(s"Error: $e")
}
user onComplete {
case Success(j) => logger.debug(s"User: ${j.toString()}")
case Failure(e) => logger.debug(s"Error: $e")
}
all onComplete { case _ => dispatch.Http.shutdown() }