aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/scala/async/run/futures/FutureSpec.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-12-11 21:30:35 +1000
committerJason Zaugg <jzaugg@gmail.com>2014-12-15 12:55:30 +1000
commit1333b3837d405c31baaa44d1db89aab0f7d09349 (patch)
treebcceb74cff609645543c07c7114ef24a468360d5 /src/test/scala/scala/async/run/futures/FutureSpec.scala
parent61b4c183fa2392522051305ec12ab5f433cc09a7 (diff)
downloadscala-async-1333b3837d405c31baaa44d1db89aab0f7d09349.tar.gz
scala-async-1333b3837d405c31baaa44d1db89aab0f7d09349.tar.bz2
scala-async-1333b3837d405c31baaa44d1db89aab0f7d09349.zip
Avoid unbounded stack consumption for synchronous control flow
Previously, as sequence of state transitions that did not pass through an asynchrous boundary incurred stack frames. The trivial loop in the enclosed test case would then overflow the stack. This commit merges the `resume` and `apply(tr: Try[Any])` methods into a `apply`. It changes the body of this method to be an infinite loop with returns at the terminal points in the state machine (or at a terminal failure.) To allow merging of these previously separate matches, states that contain an await are now allocated two state ids: one for the setup code that calls `onComplete`, and one for the code in the continuation that records the result and advances the state machine. Fixes #93
Diffstat (limited to 'src/test/scala/scala/async/run/futures/FutureSpec.scala')
-rw-r--r--src/test/scala/scala/async/run/futures/FutureSpec.scala7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/test/scala/scala/async/run/futures/FutureSpec.scala b/src/test/scala/scala/async/run/futures/FutureSpec.scala
index 1761db5..25be0b1 100644
--- a/src/test/scala/scala/async/run/futures/FutureSpec.scala
+++ b/src/test/scala/scala/async/run/futures/FutureSpec.scala
@@ -134,6 +134,13 @@ class FutureSpec {
Await.result(future1, defaultTimeout) mustBe ("10-14")
intercept[NoSuchElementException] { Await.result(future2, defaultTimeout) }
}
+
+ @Test def mini() {
+ val future4 = async {
+ await(Future.successful(0)).toString
+ }
+ Await.result(future4, defaultTimeout)
+ }
@Test def `recover from exceptions`() {
val future1 = Future(5)