本文整理了Java中com.englishtown.promises.Promise.then()
方法的一些代码示例,展示了Promise.then()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Promise.then()
方法的具体详情如下:
包路径:com.englishtown.promises.Promise
类名称:Promise
方法名:then
暂无
代码示例来源:origin: ef-labs/when.java
@Override
public <T, U> Promise<U> when(T x, Function<T, ? extends Thenable<U>> onFulfilled, Function<Throwable, ? extends Thenable<U>> onRejected) {
Promise<T> p = resolve(x);
return p.then(onFulfilled, onRejected);
}
代码示例来源:origin: com.englishtown/vertx-mod-jersey
/**
* Returns a promise for asynchronously creating a {@link com.englishtown.vertx.jersey.JerseyServer}.
* The promise type matches the WhenContainer signature to facilitate parallel deployments.
*
* @param config the jersey json configuration
* @return a promise for an empty string
*/
@Override
public Promise<String> createServerSimple(JsonObject config) {
return createServer(config).then(jerseyServer -> when.resolve(""));
}
代码示例来源:origin: com.englishtown.vertx/vertx-jersey
/**
* Returns a promise for asynchronously creating a {@link com.englishtown.vertx.jersey.JerseyServer}.
* The promise type matches the WhenContainer signature to facilitate parallel deployments.
*
* @return a promise for an empty string
*/
@Override
public Promise<String> createServerSimple() {
return createServer().then(jerseyServer -> when.resolve(""));
}
代码示例来源:origin: ef-labs/vertx-jersey
/**
* Returns a promise for asynchronously creating a {@link com.englishtown.vertx.jersey.JerseyServer}.
* The promise type matches the WhenContainer signature to facilitate parallel deployments.
*
* @return a promise for an empty string
*/
@Override
public Promise<String> createServerSimple() {
return createServer().then(jerseyServer -> when.resolve(""));
}
代码示例来源:origin: ef-labs/vertx-jersey
@Test
public void testCreateServer_Success() throws Exception {
when(result.succeeded()).thenReturn(true);
whenJerseyServer.createServer()
.then(done.onFulfilled, done.onRejected);
verify(server).start(any(), any(), handlerCaptor.capture());
handlerCaptor.getValue().handle(result);
done.assertFulfilled();
}
代码示例来源:origin: ef-labs/vertx-jersey
@Test
public void testCreateServer_Fail() throws Exception {
when(result.succeeded()).thenReturn(false);
whenJerseyServer.createServer()
.then(done.onFulfilled, done.onRejected);
verify(server).start(any(), any(), handlerCaptor.capture());
handlerCaptor.getValue().handle(result);
done.assertRejected();
}
代码示例来源:origin: ef-labs/when.java
@Test
public void testAny_should_resolve_to_undefined_with_empty_input_array() throws Exception {
List<Promise<Integer>> input = new ArrayList<>();
when.any(input).then(
result -> {
assertNull(result);
return null;
},
fail.onRejected
).then(done.onFulfilled, done.onRejected);
done.assertFulfilled();
}
代码示例来源:origin: ef-labs/when.java
@Test
@SuppressWarnings("unchecked")
public void testJoin_should_join_promises_array() throws Exception {
when.join(resolved(1), resolved(2), resolved(3)).<Integer>then(
results -> {
assertThat(results, is(Arrays.asList(1, 2, 3)));
return null;
}
).then(done.onFulfilled, done.onRejected);
done.assertFulfilled();
}
代码示例来源:origin: ef-labs/when.java
@Test
public void testReduce_should_allow_sparse_array_input_with_initial() throws Exception {
List<Promise<Integer>> input = Arrays.asList(null, null, resolved(1), null, resolved(1), resolved(1));
when.reduce(input, this::plus, resolved(1))
.<Integer>then(
result -> {
assertEquals(4, result.intValue());
return null;
})
.then(done.onFulfilled, done.onRejected);
done.assertFulfilled();
}
代码示例来源:origin: ef-labs/when.java
@Test
public void testReduce_should_reduce_promised_values_with_initial_promise() throws Exception {
List<Promise<Integer>> input = Arrays.asList(when.resolve(1), when.resolve(2), when.resolve(3));
when.reduce(input, this::plus, when.resolve(1))
.<Integer>then(
result -> {
assertEquals(7, result.intValue());
return null;
})
.then(done.onFulfilled, done.onRejected);
done.assertFulfilled();
}
代码示例来源:origin: ef-labs/when.java
@Test
public void testSome_should_resolve_promises_array() throws Exception {
List<Promise<Integer>> input = Arrays.asList(when.resolve(1), when.resolve(2), when.resolve(3));
when.some(input, 2).<Integer>then(
results -> {
assertEquals(2, results.size());
assertTrue(isSubset(results, Arrays.asList(1, 2, 3)));
return null;
}).then(done.onFulfilled, done.onRejected);
done.assertFulfilled();
}
代码示例来源:origin: ef-labs/when.java
@Test
public void testRace_should_fulfill_when_winner_fulfills() throws Exception {
Deferred<Sentinel> d1 = when.defer();
Deferred<Sentinel> d2 = when.defer();
when.race(Arrays.asList(d1.getPromise(), d2.getPromise(), fulfilled))
.then(x -> {
assertEquals(sentinel, x);
return null;
}, fail.onRejected)
.then(done.onFulfilled, done.onRejected);
done.assertFulfilled();
}
代码示例来源:origin: ef-labs/when.java
@Test
public void testPromise_then_should_allow_null_and_undefined() {
assertNotNull(when.defer().getPromise().then(null));
assertNotNull(when.defer().getPromise().then(null, null));
}
代码示例来源:origin: ef-labs/when.java
@Test
public void testPromise_then_should_allow_functions_and_null_or_undefined_to_be_mixed() {
assertNotNull(when.defer().getPromise().then(f1, null));
assertNotNull(when.defer().getPromise().then(null, f2));
}
代码示例来源:origin: ef-labs/when.java
@Test
public void testFlow_should_catch_rejections() throws Exception {
rejected(sentinelEx).<Sentinel>otherwise((e) -> {
assertEquals(e, sentinelEx);
return null;
}).then(done.onFulfilled, done.onRejected);
done.assertFulfilled();
}
代码示例来源:origin: ef-labs/when.java
@Test
public void testPromise_inspect_when_inspecting_promises_should_return_rejected_state_for_rejected_promise() {
Promise<Object> promise = when.reject(sentinelEx);
promise.then(fail.onFulfilled, (t) -> {
assertRejected(promise.inspect(), sentinelEx);
return null;
}).ensure(done::fulfill);
done.assertFulfilled();
}
代码示例来源:origin: ef-labs/when.java
@Test
public void testElse_should_resolve_normally_if_previous_promise_doesnt_fail() throws Exception {
when.resolve(input)
.orElse(resolved(sentinel))
.then((val) -> {
assertEquals(input, val);
return null;
})
.ensure(done::fulfill);
done.assertFulfilled();
}
代码示例来源:origin: ef-labs/vertx-jersey
private void runTest(String role, int status) {
getWhenHttpClient().request(HttpMethod.GET, 8080, "localhost", BASE_PATH + role)
.then(response -> {
assertEquals(status, response.statusCode());
testComplete();
return null;
})
.otherwise(this::onRejected);
await();
}
代码示例来源:origin: ef-labs/vertx-jersey
@Test
public void testGet() throws Exception {
getWhenHttpClient().requestAbs(HttpMethod.GET, "http://localhost:8080/when")
.then(response -> {
assertEquals(200, response.statusCode());
testComplete();
return null;
})
.otherwise(this::onRejected);
await();
}
代码示例来源:origin: ef-labs/vertx-jersey
@Test
public void testGet() throws Exception {
getWhenHttpClient().requestAbs(HttpMethod.GET, BASE_PATH)
.then(response -> {
assertEquals(200, response.statusCode());
String header = response.getHeader(PoweredByResponseFilter.HEADER_X_POWERED_BY);
assertEquals(PoweredByResponseFilter.HEADER_X_POWERED_BY_VALUE, header);
testComplete();
return null;
})
.otherwise(this::onRejected);
await();
}
内容来源于网络,如有侵权,请联系作者删除!