Renaming onResult to onSuccess and onException to onFailure

This commit is contained in:
Viktor Klang 2011-12-12 20:09:26 +01:00
parent 2d418c188f
commit 67c782f82c
6 changed files with 14 additions and 14 deletions

View file

@ -60,7 +60,7 @@ public class JavaFutureTests {
final CountDownLatch latch = new CountDownLatch(1);
Promise<String> cf = Futures.promise(system.dispatcher());
Future<String> f = cf;
f.onResult(new Procedure<String>() {
f.onSuccess(new Procedure<String>() {
public void apply(String result) {
if (result.equals("foo"))
latch.countDown();
@ -77,7 +77,7 @@ public class JavaFutureTests {
final CountDownLatch latch = new CountDownLatch(1);
Promise<String> cf = Futures.promise(system.dispatcher());
Future<String> f = cf;
f.onException(new Procedure<Throwable>() {
f.onFailure(new Procedure<Throwable>() {
public void apply(Throwable t) {
if (t instanceof NullPointerException)
latch.countDown();

View file

@ -394,7 +394,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa
"receiveShouldExecuteOnComplete" in {
val latch = new StandardLatch
val actor = system.actorOf[TestActor]
actor ? "Hello" onResult { case "World" latch.open }
actor ? "Hello" onSuccess { case "World" latch.open }
assert(latch.tryAwait(5, TimeUnit.SECONDS))
actor.stop()
}
@ -427,12 +427,12 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa
val latch = new StandardLatch
val f2 = Future { latch.tryAwait(5, TimeUnit.SECONDS); "success" }
f2 foreach (_ throw new ThrowableTest("dispatcher foreach"))
f2 onResult { case _ throw new ThrowableTest("dispatcher receive") }
f2 onSuccess { case _ throw new ThrowableTest("dispatcher receive") }
val f3 = f2 map (s s.toUpperCase)
latch.open
assert(Block.sync(f2, timeout.duration) === "success")
f2 foreach (_ throw new ThrowableTest("current thread foreach"))
f2 onResult { case _ throw new ThrowableTest("current thread receive") }
f2 onSuccess { case _ throw new ThrowableTest("current thread receive") }
assert(Block.sync(f3, timeout.duration) === "SUCCESS")
}
}

View file

@ -295,7 +295,7 @@ object Future {
def flow[A](body: A @cps[Future[Any]])(implicit dispatcher: MessageDispatcher): Future[A] = {
val future = Promise[A]
dispatchTask({ ()
(reify(body) foreachFull (future success, future failure): Future[Any]) onException {
(reify(body) foreachFull (future success, future failure): Future[Any]) onFailure {
case e: Exception future failure e
}
}, true)
@ -420,13 +420,13 @@ sealed trait Future[+T] extends japi.Future[T] with Block.Blockable[T] {
* When the future is completed with a valid result, apply the provided
* PartialFunction to the result. See `onComplete` for more details.
* <pre>
* future onResult {
* future onSuccess {
* case Foo target ! "foo"
* case Bar target ! "bar"
* }
* </pre>
*/
final def onResult(pf: PartialFunction[T, Unit]): this.type = onComplete {
final def onSuccess(pf: PartialFunction[T, Unit]): this.type = onComplete {
_.value match {
case Some(Right(r)) if pf isDefinedAt r pf(r)
case _
@ -437,12 +437,12 @@ sealed trait Future[+T] extends japi.Future[T] with Block.Blockable[T] {
* When the future is completed with an exception, apply the provided
* PartialFunction to the exception. See `onComplete` for more details.
* <pre>
* future onException {
* future onFailure {
* case NumberFormatException target ! "wrong format"
* }
* </pre>
*/
final def onException(pf: PartialFunction[Throwable, Unit]): this.type = onComplete {
final def onFailure(pf: PartialFunction[Throwable, Unit]): this.type = onComplete {
_.value match {
case Some(Left(ex)) if pf isDefinedAt ex pf(ex)
case _

View file

@ -8,8 +8,8 @@ import akka.actor.Timeout
/* Java API */
trait Future[+T] { self: akka.dispatch.Future[T]
private[japi] final def onResult[A >: T](proc: Procedure[A]): this.type = self.onResult({ case r proc(r.asInstanceOf[A]) }: PartialFunction[T, Unit])
private[japi] final def onException(proc: Procedure[Throwable]): this.type = self.onException({ case t: Throwable proc(t) }: PartialFunction[Throwable, Unit])
private[japi] final def onSuccess[A >: T](proc: Procedure[A]): this.type = self.onSuccess({ case r proc(r.asInstanceOf[A]) }: PartialFunction[T, Unit])
private[japi] final def onFailure(proc: Procedure[Throwable]): this.type = self.onFailure({ case t: Throwable proc(t) }: PartialFunction[Throwable, Unit])
private[japi] final def onComplete[A >: T](proc: Procedure[akka.dispatch.Future[A]]): this.type = self.onComplete(proc(_))
private[japi] final def map[A >: T, B](f: JFunc[A, B]): akka.dispatch.Future[B] = self.map(f(_))
private[japi] final def flatMap[A >: T, B](f: JFunc[A, akka.dispatch.Future[B]]): akka.dispatch.Future[B] = self.flatMap(f(_))

View file

@ -79,7 +79,7 @@ Since Akka runs on the JVM there are still some rules to be followed.
// Very bad, shared mutable state,
// will break your application in weird ways
Future { state = NewState }
anotherActor ? message onResult { r => state = r }
anotherActor ? message onSuccess { r => state = r }
// Very bad, "sender" changes for every message,
// shared mutable state bug

View file

@ -306,7 +306,7 @@ future.
.. warning::
When using future callbacks, such as ``onComplete``, ``onResult``, and ``onTimeout``,
When using future callbacks, such as ``onComplete``, ``onSuccess``, and ``onFailure``,
inside actors you need to carefully avoid closing over the containing actors
reference, i.e. do not call methods or access mutable state on the enclosing actor
from within the callback. This would break the actor encapsulation and may