本文整理了Java中io.vertx.core.Future.future()
方法的一些代码示例,展示了Future.future()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Future.future()
方法的具体详情如下:
包路径:io.vertx.core.Future
类名称:Future
方法名:future
[英]Create a future that hasn't completed yet
[中]创造一个尚未完成的未来
代码示例来源:origin: eclipse-vertx/vert.x
/**
* Map the result of a future to a specific {@code value}.<p>
*
* When this future succeeds, this {@code value} will complete the future returned by this method call.<p>
*
* When this future fails, the failure will be propagated to the returned future.
*
* @param value the value that eventually completes the mapped future
* @return the mapped future
*/
default <V> Future<V> map(V value) {
Future<V> ret = Future.future();
setHandler(ar -> {
if (ar.succeeded()) {
ret.complete(value);
} else {
ret.fail(ar.cause());
}
});
return ret;
}
代码示例来源:origin: vert-x3/vertx-examples
private Future<String> anAsyncAction() {
Future<String> future = Future.future();
// mimic something that take times
vertx.setTimer(100, l -> future.complete("world"));
return future;
}
代码示例来源:origin: eclipse-vertx/vert.x
throw new NullPointerException();
Future<U> ret = Future.future();
setHandler(ar -> {
if (ar.succeeded()) {
apply = mapper.apply(ar.result());
} catch (Throwable e) {
ret.fail(e);
return;
ret.fail(ar.cause());
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testFailedFutureOtherwise() {
Future<String> f = Future.future();
testFailedOtherwise(f, f);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCompositeFail() {
Throwable cause = new Throwable();
Future<Object> f1 = Future.future();
Future<Object> f2 = Future.future();
CompositeFuture composite = CompositeFuture.all(f1, f2);
Checker<CompositeFuture> checker = new Checker<>(composite);
composite.fail(cause);
checker.assertFailed(cause);
f1.complete();
f2.complete();
checker.assertFailed(cause);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testMapFails() {
RuntimeException cause = new RuntimeException();
Future<Integer> fut = Future.future();
Future<Object> mapped = fut.map(i -> {
throw cause;
});
Checker<Object> checker = new Checker<>(mapped);
fut.fail(cause);
checker.assertFailed(cause);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testToString() {
assertEquals("Future{unresolved}", Future.future().toString());
assertEquals("Future{result=abc}", Future.succeededFuture("abc").toString());
assertEquals("Future{cause=It's like that, and that's the way it is}", Future.failedFuture("It's like that, and that's the way it is").toString());
Future<String> f = Future.future();
f.complete("abc");
assertEquals("Future{result=abc}", f.toString());
f = Future.future();
f.fail("abc");
assertEquals("Future{cause=abc}", f.toString());
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testFailedMapperFutureRecover() {
Future<String> f = Future.future();
Future<String> r = f.recover(t -> {
throw new RuntimeException("throw");
});
f.fail("recovered");
assertTrue(r.failed());
assertEquals(r.cause().getMessage(), "throw");
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testFailFutureToHandler() {
Throwable cause = new Throwable();
Consumer<Handler<AsyncResult<String>>> consumer = handler -> {
handler.handle(Future.failedFuture(cause));
};
Future<String> fut = Future.future();
consumer.accept(fut);
assertTrue(fut.isComplete());
assertTrue(fut.failed());
assertEquals(cause, fut.cause());
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testFutureOtherwiseEmpty() {
Future<String> f = Future.future();
testOtherwiseEmpty(f, f);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testComposeFails() {
RuntimeException cause = new RuntimeException();
Future<String> f1 = Future.future();
Future<Integer> f2 = Future.future();
Checker<Integer> checker = new Checker<>(f2);
f1.compose(string -> { throw cause; }, f2);
f1.complete("foo");
checker.assertFailed(cause);
Future<String> f3 = Future.future();
Future<Integer> f4 = f3.compose(string -> { throw cause; });
checker = new Checker<>(f4);
f3.complete("foo");
checker.assertFailed(cause);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testRecoverFailureWithSuccess() {
Future<String> f = Future.future();
Future<String> r = f.recover(t -> Future.succeededFuture(t.getMessage()));
Checker<String> checker = new Checker<>(r);
checker.assertNotCompleted();
f.fail("recovered");
checker.assertSucceeded("recovered");
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testComposeSuccessToFailure() {
Throwable cause = new Throwable();
AtomicReference<String> ref = new AtomicReference<>();
Future<Integer> c = Future.future();
Future<String> f3 = Future.future();
Future<Integer> f4 = f3.compose(string -> {
ref.set(string);
return c;
});
Checker<Integer> checker = new Checker<>(f4);
f3.complete("abcdef");
c.fail(cause);
checker.assertFailed(cause);
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testFailedMapperFutureRecover() {
Future<String> f = Future.future();
Future<String> r = f.recover(t -> {
throw new RuntimeException("throw");
});
f.fail("recovered");
assertTrue(r.failed());
assertEquals(r.cause().getMessage(), "throw");
}
代码示例来源:origin: eclipse-vertx/vert.x
throw new NullPointerException();
Future<U> ret = Future.future();
setHandler(ar -> {
if (ar.succeeded()) {
mapped = mapper.apply(ar.result());
} catch (Throwable e) {
ret.fail(e);
return;
ret.complete(mapped);
} else {
ret.fail(ar.cause());
代码示例来源:origin: vert-x3/vertx-examples
private Future<String> anotherAsyncAction(String name) {
Future<String> future = Future.future();
// mimic something that take times
vertx.setTimer(100, l -> future.complete("hello " + name));
return future;
}
代码示例来源:origin: eclipse-vertx/vert.x
private void testAnyFailed(BiFunction<Future<String>, Future<Integer>, CompositeFuture> any) {
Future<String> f1 = Future.future();
Future<Integer> f2 = Future.future();
CompositeFuture composite = any.apply(f1, f2);
Checker<CompositeFuture> checker = new Checker<>(composite);
f1.fail("failure");
checker.assertNotCompleted();
Throwable cause = new Exception();
f2.fail(cause);
checker.assertFailed(cause);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testFailedFutureOtherwiseApplyFunction() {
Future<String> f = Future.future();
testFailedOtherwiseApplyFunction(f, f);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCompositeFutureToList() {
Future<String> f1 = Future.future();
Future<Integer> f2 = Future.future();
CompositeFuture composite = CompositeFuture.all(f1, f2);
assertEquals(Arrays.asList(null, null), composite.list());
f1.complete("foo");
assertEquals(Arrays.asList("foo", null), composite.list());
f2.complete(4);
assertEquals(Arrays.asList("foo", 4), composite.list());
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testOtherwiseFails() {
RuntimeException cause = new RuntimeException("throw");
Future<String> f = Future.future();
Future<String> r = f.otherwise(t -> {
throw cause;
});
Checker<String> checker = new Checker<>(r);
checker.assertNotCompleted();
f.fail("recovered");
checker.assertFailed(cause);
}
内容来源于网络,如有侵权,请联系作者删除!