You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "mdedetrich (via GitHub)" <gi...@apache.org> on 2023/05/22 14:33:35 UTC

[GitHub] [incubator-pekko-management] mdedetrich commented on pull request #74: Replace future flatMap + recoverWith combo with transform

mdedetrich commented on PR #74:
URL: https://github.com/apache/incubator-pekko-management/pull/74#issuecomment-1557331560

   @lolgab So we had this discussion on discord (see https://discord.com/channels/632150470000902164/632150470000902166/1110163014398787625) but tl;dr the usage of `Function` here is misleading and it should really be a `PartialFunction` because in the failure case it doesn't actually create a match error, it in fact passes through just like a `PartialFunction` does, you can verify this in Scala repl i.e.
   
   ```
   scala> class MyException extends Exception
   class MyException
   
   scala> val f1 = Future.failed(new MyException)
   val f1: scala.concurrent.Future[Nothing] = Future(Failure(MyException))
   
   scala> val f2 = Future.failed(new RuntimeException("bleh"))
   val f2: scala.concurrent.Future[Nothing] = Future(Failure(java.lang.RuntimeException: bleh))
   
   scala> f1.transform {
        | case Success(a) => Success(a)
        | case Failure(_: MyException) => Success("a")
        | }
                       ^
          warning: match may not be exhaustive.
          It would fail on the following input: Failure((x: Throwable forSome x not in MyException))
   val res3: scala.concurrent.Future[String] = Future(<not completed>)
   
   scala> f2.transform {
        | case Success(a) => Success(a)
        | case Failure(_: MyException) => Success("a")
        | }
                       ^
          warning: match may not be exhaustive.
          It would fail on the following input: Failure((x: Throwable forSome x not in MyException))
   val res4: scala.concurrent.Future[String] = Future(<not completed>)
   
   scala> f2.onComplete {
        | case Success(a) => println(s"success :${a.toString}")
        | case Failure(b) => println(s"failure :${b.toString}")
        | }
   failure :java.lang.RuntimeException: bleh
   ```
   
   For the success case it would create a match error but as noted before those cases shouldn't occur for those specific parts of the code.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org