From b008fd686c46f293457f58c2ecadc1bf32208051 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Mon, 20 May 2013 16:13:09 -0300 Subject: [PATCH] remove nasty bug in monad injection due to eager evaluation --- modules/common/src/main/PackageObject.scala | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/common/src/main/PackageObject.scala b/modules/common/src/main/PackageObject.scala index 633edeac04..8fc717cdd1 100644 --- a/modules/common/src/main/PackageObject.scala +++ b/modules/common/src/main/PackageObject.scala @@ -123,7 +123,7 @@ trait WithPlay extends Zeros { self: PackageObject ⇒ def void: Funit = fua map (_ ⇒ Unit) - def inject[B](b: B): Fu[B] = fua map (_ ⇒ b) + def inject[B](b: ⇒ B): Fu[B] = fua map (_ ⇒ b) def effectFold(fail: Exception ⇒ Unit, succ: A ⇒ Unit) { fua onComplete { @@ -152,13 +152,6 @@ trait WithPlay extends Zeros { self: PackageObject ⇒ case e: Exception ⇒ effect(e) }) - def nevermind[A: Zero] = fua recover { - case e: lila.common.LilaException ⇒ { - logwarn(e.getMessage) - ∅[A] - } - } - def thenPp: Fu[A] = fua ~ { _.effectFold( e ⇒ logwarn("[failure] " + e), @@ -167,6 +160,16 @@ trait WithPlay extends Zeros { self: PackageObject ⇒ } } + implicit final class LilaPimpedFutureZero[A: Zero](fua: Fu[A]) { + + def nevermind = fua recover { + case e: lila.common.LilaException ⇒ { + logwarn(e.getMessage) + ∅[A] + } + } + } + implicit final class LilaPimpedFutureOption[A](fua: Fu[Option[A]]) { def flatten(msg: ⇒ String): Fu[A] = fua flatMap {