Permalink
Browse files

Example outputs

  • Loading branch information...
1 parent c0e2a94 commit 7c4937aaf39c7f23e15562f2abbec440e1cfa244 @Srirangan committed Jan 9, 2013
Showing with 23 additions and 3 deletions.
  1. +23 −3 public/posts/2013-01-first-steps-with-scala-futures.html
@@ -10,8 +10,6 @@
// `future` blocks asynchronously execute in a different thread and return a `val`
// asynchronous results can be trapped via `onSuccess`, `onFailure` and `onComplete` callbacks
- Console.println("Waiting..")
-
val sayHello = future {
Thread.sleep(1000)
"hello"
@@ -21,9 +19,14 @@
case message => Console.println(s"He said '$message'")
}
+ Console.println("Waiting..")
+
Thread.sleep(2000)
- Console.println("Try dividing by zero")
+ // output
+ //
+ // Waiting..
+ // He said 'hello'
val tryDivideByZero = future {
Thread.sleep(1000)
@@ -34,7 +37,14 @@
case e: ArithmeticException => Console.println(s"Don't be silly!")
}
+ Console.println("Try dividing by zero")
+
Thread.sleep(2000)
+
+ // output
+ //
+ // Try dividing by zero
+ // Don't be silly!
</pre>
<pre>
// example 2
@@ -62,6 +72,11 @@
}
Thread.sleep(2000)
+
+ // output
+ //
+ // i love you
+ // not really
</pre>
<pre>
// example 3
@@ -93,6 +108,11 @@
Console.println("Do I win?")
Thread.sleep(2000)
+
+ // output
+ //
+ // Do I win?
+ // yes|no
</pre>
<p>

0 comments on commit 7c4937a

Please sign in to comment.