Created
September 1, 2011 19:21
-
-
Save bruntonspall/1187013 to your computer and use it in GitHub Desktop.
Scala Samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for(i <- 1 to 10) { | |
| if (isSocketOpen) return | |
| Thread.sleep(duration/10) | |
| } | |
| sys.error("Timed out") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val range: Seq[Int] = 1 to MAX_CONNECTION_ATTEMPTS | |
| range.flatMap(checkSocketOpen).headOption match { | |
| case None => sys.error("Timed out") | |
| case _ => | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| spawn { | |
| val server = new ServerSocket(9998) | |
| server.accept().close() | |
| server.close() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| evaluating { | |
| task.execute() | |
| } should produce [RuntimeException] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment