I am using the dispatch reboot library version 0.9.5 (http://dispatch.databinder.net/Dispatch.html) in my project. Via sbt I have the following line:
libraryDependencies += "net.databinder.dispatch" %% "dispatch-core" % "0.9.5"
In the scala (2.9.2) repl (started using sbt console
to get the appropriate dependency) and independent of my code I run the following session:
import dispatch._
import java.util.concurrent.TimeUnit._
val spoo = Http.threads(1).waiting( Duration(10, SECONDS ) )
(I believe that the third line sets up my own threadpool with one thread and a timeout of 10 seconds).
I then run this code repeatedly (in paste mode), to submit a future to fetch a particular url and then print the status code (asynchronously):
spoo(url("http://www.evapcool.com/products/commercial/")).either
.map {
case Right(r) => println( "S: " + r.getStatusCode())
case Left(e) => println( "E: " + e.toString ) }
Each time I run this line I wait for the status code to get printed before running the line again. For the first twenty to forty calls it works as expected. Then it reliably fails to report either a successful page reply or an exception. My assumption was that if this is caused by a timeout, I should expect the callback to fire after 10 seconds with the Left
clause of the Either
containing some form of timeout exception. But my experience is that this never comes.
Can anyone help tell me what I'm doing wrong?
Update
By the way, I am aware that there is a similar question (with answer) here but I am looking for the official (i.e. intended by the library author) way to handle timeouts - and it appears to me that this is what the waiting
method is designed for