Advertisement
Guest User

Untitled

a guest
May 18th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.35 KB | None | 0 0
  1.  def zeroOnArithmeticException(x: Future[Int]): Future[Int] = {
  2.     val p = promise[Int]
  3.     x onSuccess {
  4.       case luku => p.trySuccess(luku)
  5.     }
  6.     x onFailure {
  7.       case failure => failure match{
  8.         case e: ArithmeticException => p.tryCompleteWith(future(0))
  9.         case muut => p.tryFailure(muut)
  10.       }
  11.     }    
  12.     p.future
  13.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement