reactor.core.publisher.Mono.materialize()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(318)

本文整理了Java中reactor.core.publisher.Mono.materialize()方法的一些代码示例,展示了Mono.materialize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.materialize()方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:materialize

Mono.materialize介绍

[英]Transform incoming onNext, onError and onComplete signals into Signal instances, materializing these signals. Since the error is materialized as a Signal, the propagation will be stopped and onComplete will be emitted. Complete signal will first emit a Signal.complete() and then effectively complete the flux. All these Signal have a Context associated to them.
[中]将传入的onNext、onError和onComplete信号转换为信号实例,具体化这些信号。由于错误被具体化为一个信号,传播将停止并发出onComplete。完成信号将首先发出一个信号。完成()然后有效地完成通量。所有这些信号都有一个与之相关的上下文。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Test
public void errorBeforeFirstItem() throws Exception {
  IllegalStateException error = new IllegalStateException("boo");
  Mono<Void> completion = Mono.<String>error(error).as(this::sendOperator);
  Signal<Void> signal = completion.materialize().block();
  assertNotNull(signal);
  assertSame("Unexpected signal: " + signal, error, signal.getThrowable());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void writeMultipleItems() throws Exception {
  List<String> items = Arrays.asList("one", "two", "three");
  Mono<Void> completion = Flux.fromIterable(items).as(this::sendOperator);
  Signal<Void> signal = completion.materialize().block();
  assertNotNull(signal);
  assertTrue("Unexpected signal: " + signal, signal.isOnComplete());
  assertEquals(3, this.writer.items.size());
  assertEquals("one", this.writer.items.get(0));
  assertEquals("two", this.writer.items.get(1));
  assertEquals("three", this.writer.items.get(2));
  assertTrue(this.writer.completed);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void writeOneItem() throws Exception {
  Mono<Void> completion = Flux.just("one").as(this::sendOperator);
  Signal<Void> signal = completion.materialize().block();
  assertNotNull(signal);
  assertTrue("Unexpected signal: " + signal, signal.isOnComplete());
  assertEquals(1, this.writer.items.size());
  assertEquals("one", this.writer.items.get(0));
  assertTrue(this.writer.completed);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void completionBeforeFirstItem() throws Exception {
  Mono<Void> completion = Flux.<String>empty().as(this::sendOperator);
  Signal<Void> signal = completion.materialize().block();
  assertNotNull(signal);
  assertTrue("Unexpected signal: " + signal, signal.isOnComplete());
  assertEquals(0, this.writer.items.size());
  assertTrue(this.writer.completed);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void errorAfterMultipleItems() throws Exception {
  IllegalStateException error = new IllegalStateException("boo");
  Flux<String> publisher = Flux.generate(() -> 0, (idx , subscriber) -> {
    int i = ++idx;
    subscriber.next(String.valueOf(i));
    if (i == 3) {
      subscriber.error(error);
    }
    return i;
  });
  Mono<Void> completion = publisher.as(this::sendOperator);
  Signal<Void> signal = completion.materialize().block();
  assertNotNull(signal);
  assertSame("Unexpected signal: " + signal, error, signal.getThrowable());
  assertEquals(3, this.writer.items.size());
  assertEquals("1", this.writer.items.get(0));
  assertEquals("2", this.writer.items.get(1));
  assertEquals("3", this.writer.items.get(2));
  assertSame(error, this.writer.error);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void materialize() {
  StepVerifier.create(Mono.just("Three")
              .materialize())
        .expectNextMatches(s -> s.isOnNext() && s.get()
                             .equals("Three"))
        .verifyComplete();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void completeOnlyBackpressured() {
  AssertSubscriber<Signal<Integer>> ts = AssertSubscriber.create(0L);
  
  Mono.<Integer>empty().materialize()
  .subscribe(ts);
  
  ts.assertNoValues()
  .assertNoError()
  .assertNotComplete();
  
  ts.request(1);
  
  ts.assertValues(Signal.complete())
  .assertNoError()
  .assertComplete();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void errorOnlyBackpressured() {
  AssertSubscriber<Signal<Integer>> ts = AssertSubscriber.create(0L);
  RuntimeException ex = new RuntimeException();
  
  Mono.<Integer>error(ex).materialize()
  .subscribe(ts);
  
  ts.assertNoValues()
  .assertNoError()
  .assertNotComplete();
  
  ts.request(1);
  
  ts.assertValues(Signal.error(ex))
  .assertNoError()
  .assertComplete();
}

代码示例来源:origin: com.aol.cyclops/cyclops-reactor

/**
 * @return
 * @see reactor.core.publisher.Mono#materialize()
 */
public final Mono<Signal<T>> materialize() {
  return boxed.materialize();
}
/**

代码示例来源:origin: io.projectreactor.addons/reactor-extra

reader.apply(key)
 .switchIfEmpty(otherSupplier.get()
               .materialize()
               .flatMap(signal -> writer.apply(key, signal)
                            .then(Mono.just(signal))

代码示例来源:origin: io.projectreactor.addons/reactor-extra

return otherSupplier -> Mono.defer(() ->
    Mono.justOrEmpty(cacheMap.get(key))
      .switchIfEmpty(otherSupplier.get().materialize()
              .doOnNext(value -> cacheMap.put(key, value)))
      .dematerialize()

相关文章

Mono类方法