score:0
You can try something like this:
timedOutFuture = after(duration = duration, using = system.scheduler) {
Future.successfull(None)
}
Future.firstCompletedOf(Seq(youHttpRequestFuture, timedOutFuture))
Hope it helps
score:1
So I suppose you are trying to solve 2 problems. How to define a particular timeout in the configuration and then how to manage timeouts when they happen.
Define http client timeouts: You will need to update your
application.conf
to overwrite the default configuration of the http client. e.g.:spray.can { client { request-timeout = 20s } }
Managing timeouts: When you use the spray client, you will use a
pipeline
that will run the requests. It will be a function that looks something like(HttpRequest) => Future[ObjectResponse]
. The result will be aFuture
of an object you have defined ,ObjectResponse
in my example, you can resolve the future. In case a there is a timeout, theFuture
will become a RequestTimeoutException. Then you will be able to process the timeout exception with arecover
. So your code will look something like this:def sendRequestFunction(...): Future[ObjectResponse] = {...} sendRequestFunction(parameters) map (Option) // In case we get an object, we will have a Some(obj) recover { case e: RequestTimeoutException => None }
Source: stackoverflow.com
Related Query
- Retrieving http response using spray and futures with timeout
- Transforming Slick Streaming data and sending Chunked Response using Akka Http
- Compiler error on nested futures response with Play and ReactiveMongo
- Using the Http headers to unmarshall a response with spray-client
- JSON response with Http AKKA and case classes
- Sending an http response with Json content using marshallers in Akka Http
- Akka HTTP and Akka streams - using Flows with high level routes API
- How to map multiple Futures and pass them as arguments to a view using Play with Scala
- Getting an HTTP response as Array[Byte] with Scala and Dispatch
- How to complete Akka Http response with Stream and Custom Status Code
- How to support marshalling and unmarshalling in Akka HTTP with JSON Spray for HashMap fields?
- Scala futures and method call backs using spray routing
- What's the best practice to send a simply HTTP request and get its response with Akka?
- How to select multiple column from database using scala Play2.6 and with proper json response header
- Using Auto Incrementing fields with PostgreSQL and Slick
- How to http post with an empty body request using WS API in Playframework 2 / Scala?
- Using futures and Thread.sleep
- Using scala.sys.process with timeout
- How to download a HTTP resource to a file with Akka Streams and HTTP?
- Parsing multipart HTTP form data with file upload content using Scala
- Extremely slow compile time with SBT auto-reload using play! and scala-js
- Using mapTo with futures in Akka/Scala
- Chunked response handling with spray example
- Problems using protobufs with java and scala
- Using AndroidAnnotations with Scala and Gradle
- What is the difference between idle-timeout and request timeout in akka http configuration?
- Strange deserializing problems with generic types using Scala and Jackson and java.lang.Integer or scala.Int
- How to get ScalaTest correctly reporting tests results when using scalacheck with Propspec and PropertyCheck?
- How to send HTTP request using Akka with SSL certificates
- Asynchronous http requests using Netty and Scala actors
More Query from same tag
- Sorting in Spark SQL for the Month
- Type bounds in Scala Universe design
- Pattern matching lists of certain size or greater/less
- How to revert XML escaped characters (XML unescape)?
- Why does the stream never get triggered?
- Passing function with Subclass as argument to function which takes any function with Super class as parameter
- What is the purpose of Scala programming language?
- Inheriting properties among case class
- Integrating avro into sbt workflow
- Missing 'debug' command from Play 2.0 installed from Typesafe
- Scala: Append to Array within a Map
- Defining a scala Map of functions with variable return types
- define default named arguments in terms of other arguments in scala
- Prevent akka actor from restarting child actor
- ZIO scala sleep method not sleeping the thread vs. using directly Thread.sleep
- How to get methods list in scala
- running a spark application fails on EC2 with hadoop IncompatibleClassChangeError
- Split Map to multiple Maps
- Getting all Keys associated with the max value in Spark
- Compilation error following Play! Framework NewApplication guide
- pattern matching an array without redundancies
- Scala Spark - using RDD with mllib
- Scala Spark/Databricks: Efficiently load multiple partitions with different schema?
- Divide two BigInt values and cast the result to Float in Scala
- How do I run `Observable` in a separate thread?
- How to drop rows with too many NULL values?
- SPARK Yarn: Service or property not registered for Azure ServiceBus JAVA SDK
- Scala pattern matching against URLs
- Parser: Compilation error[not found: value get]
- Copy top fifteen elements from one array to another one