Removing Future.result

This commit is contained in:
Viktor Klang 2011-12-12 15:22:26 +01:00
parent 7eced71a85
commit 7026ded91d
7 changed files with 17 additions and 55 deletions

View file

@ -14,7 +14,7 @@ import com.typesafe.config.Config;
import static org.junit.Assert.*;
public class JavaExtension extends JavaExtensionSuite {
public class JavaExtension {
static class Provider implements ExtensionIdProvider {
public ExtensionId<TestExtension> lookup() {

View file

@ -7,8 +7,7 @@ import akka.testkit._
import org.scalatest.junit.JUnitSuite
import com.typesafe.config.ConfigFactory
//FIXME SOME BUG WITH COMPILER?
//class JavaExtensionSpec extends JavaExtension with JUnitSuite
class JavaExtensionSpec extends JavaExtension with JUnitSuite
object TestExtension extends ExtensionId[TestExtension] with ExtensionIdProvider {
def lookup = this

View file

@ -5,5 +5,4 @@ package akka.actor
import org.scalatest.junit.JUnitSuite
//FIXME SOME BUG WITH COMPILER?
//class JavaAPISpec extends akka.actor.JavaAPI with JUnitSuite
class JavaAPISpec extends JavaAPI with JUnitSuite

View file

@ -407,14 +407,6 @@ sealed trait Future[+T] extends japi.Future[T] with Block.Blockable[T] {
*/
def value: Option[Either[Throwable, T]]
/**
* Returns the successful result of this Future if it exists.
*/
final def result: Option[T] = value match {
case Some(Right(r)) Some(r)
case _ None
}
/**
* When this Future is completed, apply the provided function to the
* Future. If the Future has already been completed, this will apply

View file

@ -186,7 +186,7 @@ class Agent[T](initialValue: T, system: ActorSystem) {
/**
* Gets this agent's value after all currently queued updates have completed.
*/
def await(implicit timeout: Timeout): T = Block.on(future, timeout.duration).result.get
def await(implicit timeout: Timeout): T = Block.sync(future, timeout.duration)
/**
* Map this agent to a new agent, applying the function to the internal state.

View file

@ -13,10 +13,10 @@ import java.util.concurrent.TimeUnit;
public class UntypedTransactorExample {
public static void main(String[] args) throws InterruptedException {
ActorSystem application = ActorSystem.create("UntypedTransactorExample", AkkaSpec.testConf());
ActorSystem app = ActorSystem.create("UntypedTransactorExample", AkkaSpec.testConf());
ActorRef counter1 = application.actorOf(new Props().withCreator(UntypedCounter.class));
ActorRef counter2 = application.actorOf(new Props().withCreator(UntypedCounter.class));
ActorRef counter1 = app.actorOf(new Props().withCreator(UntypedCounter.class));
ActorRef counter2 = app.actorOf(new Props().withCreator(UntypedCounter.class));
counter1.tell(new Increment(counter2));
@ -28,25 +28,11 @@ public class UntypedTransactorExample {
Future future1 = counter1.ask("GetCount", timeout);
Future future2 = counter2.ask("GetCount", timeout);
Block.on(future1, d);
if (future1.isCompleted()) {
if (future1.result().isDefined()) {
int result = (Integer) future1.result().get();
System.out.println("counter 1: " + result);
}
}
int count1 = (Integer)Block.sync(future1, d);
System.out.println("counter 1: " + count1);
int count2 = (Integer)Block.sync(future2, d);
System.out.println("counter 1: " + count2);
Block.on(future2, d);
if (future2.isCompleted()) {
if (future2.result().isDefined()) {
int result = (Integer) future2.result().get();
System.out.println("counter 2: " + result);
}
}
counter1.stop();
counter2.stop();
application.stop();
app.stop();
}
}

View file

@ -79,16 +79,9 @@ public class UntypedTransactorTest {
} catch (InterruptedException exception) {
}
for (ActorRef counter : counters) {
Future future = counter.ask("GetCount", askTimeout);
Block.on(future, Duration.create(askTimeout, TimeUnit.MILLISECONDS));
if (future.isCompleted()) {
Option resultOption = future.result();
if (resultOption.isDefined()) {
Object result = resultOption.get();
int count = (Integer) result;
assertEquals(1, count);
}
}
Future<Object> future = counter.ask("GetCount", askTimeout);
int count = (Integer)Block.sync(future, Duration.create(askTimeout, TimeUnit.MILLISECONDS));
assertEquals(1, count);
}
}
@ -109,15 +102,8 @@ public class UntypedTransactorTest {
}
for (ActorRef counter : counters) {
Future future = counter.ask("GetCount", askTimeout);
Block.on(future, Duration.create(askTimeout, TimeUnit.MILLISECONDS));
if (future.isCompleted()) {
Option resultOption = future.result();
if (resultOption.isDefined()) {
Object result = resultOption.get();
int count = (Integer) result;
assertEquals(0, count);
}
}
int count = (Integer)Block.sync(future, Duration.create(askTimeout, TimeUnit.MILLISECONDS));
assertEquals(0, count);
}
}