scala/scala-async

scala.NotImplementedError when evaluating a failed Future

yanns opened this issue · 4 comments

The following worksheet:

import scala.async.Async.{async, await}
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

val f = Future.failed(new Exception())
async {
  await(f)
}

delivers the following error

scala.NotImplementedError: an implementation is missing
    at scala.Predef$.$qmark$qmark$qmark(async.sc1820668219168430883.tmp:248)
    at #worksheet#.stateMachine$1$1.<init>(async.sc1820668219168430883.tmp:7)
    at #worksheet#.#worksheet#(async.sc1820668219168430883.tmp:6)

What is the status on this. It seems to be a pretty important case of the whole async/await flow. If Exceptions cannot be thrown, then how should i have the courage to use this lib?

Thanks for the report. You can workaround this issue by annotating the type if f with something other than Future[Nothing].

val f: Future[Any] = Future.failed(new Exception())
async {
  await(f)
}

I'll include the fix for this bug in a new release of async in the coming weeks.

I can confirm the workaround works.

import scala.async.Async.{async, await}
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global

val f: Future[String] = Future.failed(new Exception("test"))
val result = async {
  await(f)
}
Await.result(result, Duration.Inf)

outputs

import scala.async.Async.{async, await}
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global

f: scala.concurrent.Future[String] = scala.concurrent.impl.Promise$KeptPromise@68c8af42
result: scala.concurrent.Future[String] = scala.concurrent.impl.Promise$DefaultPromise@7d52966f


java.lang.Exception: test
    at #worksheet#.f$lzycompute(async.sc3389584584737533063.tmp:6)
    at #worksheet#.f(async.sc3389584584737533063.tmp:6)
    at #worksheet#.get$$instance$$f(async.sc3389584584737533063.tmp:6)
    at #worksheet#.#worksheet#(async.sc3389584584737533063.tmp:25)

It means that his error would never occur in real application code.
Great!

I've just deployed scala-async 0.9.2 to Sonatype.