Case 1: With assignment, if caseCase 2: With assignment, else caseCase 3: Without assignment, if case // Does not execute onComplete()!Case 4: Without assignment, else case
Hi Eric, if you add a 'case _ => println("ohnoes")' as a catch-all in the onComplete callback, is it called?
--
Cheers,
√
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
(if (false) { Future.successful(1)} else { Future.successful(0)}) onComplete { case Success(x: Int) => println(s"CASE 4: NoAssign, else-case, onComplete: success ${x}") case Failure(x: Throwable) => println(s"CASE 4: NoAssign,else-case, onComplete: failure: ${x.toString}")}Ouch, nice catch, Stephen!
--
Cheers,
√
Hi Victor,I added the catch-all case you suggested, but it is not called. Incidentally, we saw this behavior in production code (the types and bodies of if/else were different), and we had two cases: Success(_) and Failure(_), which I think should cover everything.The fundamental question in my mind is: what is the type ofif(...) { expr } else { expr }... and if my call to onComplete() after the closing brace of the else compiles, then why is it applying only to the case where the 'else' executes?Many people (all of whom are colleagues at work :) ) are pointing out that I can surround the if/else with braces or parenthesis and the onComplete() handler is then always called. OK, that's fine...but that does not satisfy my understanding of the way I think the semantics are supposed to work. I am starting with the possibility that my understanding is wrong before asserting that the compiler is broken.I'm a bit surprised that the compiler does not infer the if/else I have above as some type (in this case, Future[Int]) and then call onComplete on the object, of type Future[Int], regardless of which of the if or else cases executes. It would seem that the behavior I'm seeing is that the onComplete() handler is only registered on the future returned by the expression after the 'else.'