mirror of
https://github.com/jlengrand/vert.x.git
synced 2026-03-10 08:51:19 +00:00
Future will fail when the handler which is passed to Future.future throws an Exception. (#3057)
* Future will fail on `Future.future` throws an Exception. Signed-off-by: iseki <admin@iseki.space> * Modify testcase and fix format. Signed-off-by: iseki <admin@iseki.space>
This commit is contained in:
@@ -36,7 +36,11 @@ public interface Future<T> extends AsyncResult<T> {
|
||||
*/
|
||||
static <T> Future<T> future(Handler<Promise<T>> handler) {
|
||||
Promise<T> promise = Promise.promise();
|
||||
handler.handle(promise);
|
||||
try {
|
||||
handler.handle(promise);
|
||||
} catch (Exception e){
|
||||
promise.tryFail(e);
|
||||
}
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
|
||||
@@ -65,14 +65,10 @@ public class FutureTest extends VertxTestBase {
|
||||
assertSame(f2, ref.get().future());
|
||||
assertEquals(1, count.get());
|
||||
new Checker<>(f2).assertFailed(cause);
|
||||
try {
|
||||
Future.future(f -> {
|
||||
throw cause;
|
||||
});
|
||||
fail();
|
||||
} catch (Exception e) {
|
||||
assertSame(cause, e);
|
||||
}
|
||||
Future f3 = Future.future(f -> {
|
||||
throw cause;
|
||||
});
|
||||
assertSame(cause, f3.cause());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user