本文整理了Java中reactor.core.publisher.Mono.delay()
方法的一些代码示例,展示了Mono.delay()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.delay()
方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:delay
[英]Create a Mono which delays an onNext signal by a given Durationon a default Scheduler and completes. If the demand cannot be produced in time, an onError will be signalled instead. The delay is introduced through the Schedulers#parallel() default Scheduler.
[中]在默认调度程序上创建一个单声道,将onNext信号延迟给定的时间并完成。如果不能及时产生需求,则会发出一个错误信号。延迟是通过调度程序#parallel()默认调度程序引入的。
代码示例来源:origin: spring-projects/spring-framework
private <T> Function<Flux<T>, Publisher<?>> reconnectFunction(ReconnectStrategy reconnectStrategy) {
return flux -> flux
.scan(1, (count, element) -> count++)
.flatMap(attempt -> Optional.ofNullable(reconnectStrategy.getTimeToNextAttempt(attempt))
.map(time -> Mono.delay(Duration.ofMillis(time), this.scheduler))
.orElse(Mono.empty()));
}
代码示例来源:origin: spring-projects/spring-framework
private Mono<String> doAsyncWork() {
return Mono.delay(Duration.ofMillis(100L)).map(l -> "123");
}
}
代码示例来源:origin: reactor/reactor-core
Mono<Integer> scenario_fastestSource() {
return Mono.first(Mono.delay(Duration.ofSeconds(4))
.map(s -> 1),
Mono.delay(Duration.ofSeconds(3))
.map(s -> 2));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void cancellation() {
Mono<Long> mono = Mono.delay(Duration.ofSeconds(60));
Future<Long> future = new MonoToListenableFutureAdapter<>(mono);
assertTrue(future.cancel(true));
assertTrue(future.isCancelled());
}
代码示例来源:origin: reactor/reactor-core
@Test//(timeout = 5000)
public void all2NonEmptyIterable() {
Assert.assertEquals(Integer.MIN_VALUE,
Mono.first(Mono.delay(Duration.ofMillis(150))
.map(i -> Integer.MIN_VALUE), Mono.delay(Duration.ofMillis(250)))
.block());
}
代码示例来源:origin: reactor/reactor-core
@Test//(timeout = 5000)
public void all2NonEmpty() {
Assert.assertEquals(Integer.MIN_VALUE,
Mono.first(Mono.delay(Duration.ofMillis(150))
.map(i -> Integer.MIN_VALUE), Mono.delay(Duration.ofMillis(250)))
.block());
}
代码示例来源:origin: spring-projects/spring-framework
Mono<Void> responseMonoVoid(ServerHttpResponse response) {
return Mono.delay(Duration.ofMillis(100))
.thenEmpty(Mono.defer(() -> response.writeWith(getBody("body"))));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void promiseDelays() throws Exception {
Tuple2<Long, String> h = Mono.delay(Duration.ofMillis(3000))
.log("time1")
.map(d -> "Spring wins")
.or(Mono.delay(Duration.ofMillis(2000)).log("time2").map(d -> "Spring Reactive"))
.flatMap(t -> Mono.just(t+ " world"))
.elapsed()
.block();
assertThat("Alternate mono not seen", h.getT2(), is("Spring Reactive world"));
System.out.println(h.getT1());
}
代码示例来源:origin: reactor/reactor-core
@Test(timeout = 5000)
public void someEmpty() {
Assert.assertNull(Mono.first(Mono.empty(), Mono.delay(Duration.ofMillis(250)))
.block());
}
代码示例来源:origin: reactor/reactor-core
@Test(timeout = 5000)
public void allEmptyIterable() {
Assert.assertNull(Mono.first(Arrays.asList(Mono.empty(),
Mono.delay(Duration.ofMillis(250))
.ignoreElement()))
.block());
}
代码示例来源:origin: spring-projects/spring-framework
Mono<Void> exchangeMonoVoid(ServerWebExchange exchange) {
return Mono.delay(Duration.ofMillis(100))
.thenEmpty(Mono.defer(() -> exchange.getResponse().writeWith(getBody("body"))));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void someEmpty() {
StepVerifier.withVirtualTime(() ->
Mono.zip(Mono.delay(Duration.ofMillis(150)).then(), Mono.delay(Duration
.ofMillis(250))))
.thenAwait(Duration.ofMillis(150))
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void testAPIDelayUntilErrorsImmediately() {
IllegalArgumentException boom = new IllegalArgumentException("boom");
StepVerifier.create(Flux.error(boom)
.delayUntil(a -> Mono.delay(Duration.ofSeconds(2))))
.expectErrorMessage("boom")
.verify(Duration.ofMillis(200)); //at least, less than 2s
}
代码示例来源:origin: reactor/reactor-core
@Test
public void apiTakeErrorBeforeDuration() {
StepVerifier.withVirtualTime(() ->
Mono.delay(Duration.ofMillis(100))
.then(Mono.error(new IllegalStateException("boom")))
.take(Duration.ofMillis(200))
)
.thenAwait(Duration.ofMillis(200))
.verifyErrorMessage("boom");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void apiTakeSchedulerShortcircuits() {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
StepVerifier.create(
Mono.delay(Duration.ofMillis(200))
.take(Duration.ofSeconds(10), vts)
)
.then(() -> vts.advanceTimeBy(Duration.ofSeconds(10)))
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void assertDurationLessThanOk() {
StepVerifier.create(Mono.delay(Duration.ofMillis(500)).then())
.expectComplete()
.verifyThenAssertThat()
.tookLessThan(Duration.ofSeconds(1));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void assertDurationMoreThanOk() {
StepVerifier.create(Mono.delay(Duration.ofMillis(500)).then())
.expectComplete()
.verifyThenAssertThat()
.tookMoreThan(Duration.ofMillis(100));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void verifyCompleteUsesDefaultTimeout() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() ->
StepVerifier.create(Mono.delay(Duration.ofMillis(150)))
.verifyComplete())
.withMessageStartingWith("VerifySubscriber timed out");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void verifyErrorUsesDefaultTimeout() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() ->
StepVerifier.create(Mono.delay(Duration.ofMillis(150)))
.verifyError())
.withMessageStartingWith("VerifySubscriber timed out");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void verifyErrorMatchesUsesDefaultTimeout() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() ->
StepVerifier.create(Mono.delay(Duration.ofMillis(150)))
.verifyErrorMatches(ignore -> true))
.withMessageStartingWith("VerifySubscriber timed out");
}
内容来源于网络,如有侵权,请联系作者删除!