use of co.paralleluniverse.fibers.Suspendable in project quasar by puniverse.
the class ProxyServerTest method testCast.
@Test
public void testCast() throws Exception {
final AtomicInteger called = new AtomicInteger(0);
final Server<?, ?, ?> a = spawnServer(false, new A() {
public int foo(String str, int x) {
throw new UnsupportedOperationException();
}
@Suspendable
public void bar(int x) {
try {
Strand.sleep(100);
called.set(x);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (SuspendExecution e) {
throw new AssertionError(e);
}
}
});
((A) a).bar(15);
assertThat(called.get(), is(0));
Thread.sleep(200);
assertThat(called.get(), is(15));
a.shutdown();
LocalActor.join(a, 100, TimeUnit.MILLISECONDS);
}
use of co.paralleluniverse.fibers.Suspendable in project quasar by puniverse.
the class AbstractFuture method get.
@Override
@Suspendable
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
try {
if (done)
return getValue();
long left = unit.toNanos(timeout);
final long deadline = System.nanoTime() + left;
Object token = sync.register();
try {
for (int i = 0; !done; i++) {
sync.await(i, left, TimeUnit.NANOSECONDS);
left = deadline - System.nanoTime();
if (left <= 0)
throw new TimeoutException();
}
} finally {
sync.unregister(token);
}
return getValue();
} catch (SuspendExecution e) {
throw new AssertionError(e);
}
}
Aggregations