Mono<T>.materialize return Flux<Signal<T>> 应该吗?

Should Mono<T>.materialize return Flux<Signal<T>>?

根据 Mono<T>.materialize() 上的 Javadoc:

Transform the incoming onNext, onError and onComplete signals into Signal. 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.

这意味着materialize编辑的Publisher return在没有错误发生的情况下至少应该发出2个信号:

然而,此方法的 return 类型是 Mono<Signal<T>>,它只允许发出单个事件。所以我很困惑。代码应该是

Flux<Signal<Integer>> mono = Mono.just(1).materialize();
StepVerifier.create(mono)
    .expectNext(Signal.next(1))
    .expectNext(Signal.complete())
    .verifyComplete();

Mono中,materialize只发出一个Signal。 Mono 只能发生 3 种情况:

  1. 单声道成功并且:发出Signal.next(value)
  2. 单声道成功但 Signal.complete() 已发出
  3. 单声道 错误Signal.error(throwable) 被发射