本文整理了Java中reactor.core.publisher.Mono.publish()
方法的一些代码示例,展示了Mono.publish()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.publish()
方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:publish
[英]Share a Mono for the duration of a function that may transform it and consume it as many times as necessary without causing multiple subscriptions to the upstream.
[中]在函数期间共享一个Mono,该函数可以根据需要多次转换和使用Mono,而不会导致对上游的多个订阅。
代码示例来源:origin: reactor/reactor-core
@Test
public void syncCancelBeforeComplete() {
assertThat(Mono.just(Mono.just(1).publish(v -> v)).flatMapMany(v -> v).blockLast()).isEqualTo(1);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void npeFunction() {
StepVerifier.create(Mono.just("Foo")
.publish(m -> null))
.expectErrorSatisfies(e -> assertThat(e)
.isInstanceOf(NullPointerException.class)
.hasMessage("The transform returned a null Mono"))
.verify();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normalCancelBeforeComplete() {
assertThat(Mono.just(Mono.just(1).hide().publish(v -> v)).flatMapMany(v -> v).blockLast()).isEqualTo(1);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void failingFunction() {
RuntimeException expected = new IllegalStateException("boom");
StepVerifier.create(Mono.just("Foo")
.publish(m -> {
throw expected;
}))
.expectErrorSatisfies(e -> assertThat(e).isSameAs(expected))
.verify();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void nullFunction() {
assertThatNullPointerException()
.isThrownBy(() -> Mono.just("Foo")
.publish(null))
.withMessage("transform");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normal() {
AtomicInteger i = new AtomicInteger();
Mono<Integer> m = Mono.fromCallable(i::incrementAndGet)
.publish(o -> o.map(s -> 2));
StepVerifier.create(m)
.expectNext(2)
.verifyComplete();
StepVerifier.create(m)
.expectNext(2)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normalHide() {
AtomicInteger i = new AtomicInteger();
Mono<Integer> m = Mono.fromCallable(i::incrementAndGet)
.hide()
.publish(o -> o.map(s -> 2));
StepVerifier.create(m)
.expectNext(2)
.verifyComplete();
StepVerifier.create(m)
.expectNext(2)
.verifyComplete();
}
代码示例来源:origin: com.aol.cyclops/cyclops-reactor
/**
* @param transform
* @return
* @see reactor.core.publisher.Mono#publish(java.util.function.Function)
*/
public final <R> Mono<R> publish(Function<? super Mono<T>, ? extends Mono<? extends R>> transform) {
return boxed.publish(transform);
}
/**
内容来源于网络,如有侵权,请联系作者删除!