Closed
Description
@RunWith(classOf[JUnit4])
class Stacksafe {
@Test
def testFib(): Unit = {
implicit val ex: ExecutionContext = new ExecutionContext {
override def execute(runnable: Runnable): Unit = runnable.run()
override def reportFailure(cause: Throwable): Unit = cause.printStackTrace()
}
def fib(n: Int, a: Long = 0, b: Long = 1): Future[Long] =
Future(a + b).flatMap { b2 =>
if (n > 0)
fib(n - 1, b, b2)
else
Future(b2)
}
val future = fib(1000)
println(Await.result(future,Duration.Inf))
}
}
It's ok with 100,but not 1000
Metadata
Metadata
Assignees
Labels
No labels