Skip to content

Instantly share code, notes, and snippets.

@bruntonspall
Created September 1, 2011 19:21
Show Gist options
  • Save bruntonspall/1187013 to your computer and use it in GitHub Desktop.
Save bruntonspall/1187013 to your computer and use it in GitHub Desktop.
Scala Samples
for(i <- 1 to 10) {
if (isSocketOpen) return
Thread.sleep(duration/10)
}
sys.error("Timed out")
val range: Seq[Int] = 1 to MAX_CONNECTION_ATTEMPTS
range.flatMap(checkSocketOpen).headOption match {
case None => sys.error("Timed out")
case _ =>
}
def checkOpen(currentTry: Int) {
if (currentTry > MAX_CONNECTION_ATTEMPTS)
sys.error("Timed out")
try new Socket(host.name, port.toInt).close()
catch { case e: IOException => {
Thread.sleep(duration/MAX_CONNECTION_ATTEMPTS)
checkOpen(currentTry + 1)
}
}
}
checkOpen(0)
spawn {
val server = new ServerSocket(9998)
server.accept().close()
server.close()
}
evaluating {
task.execute()
} should produce [RuntimeException]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment