首页 > 解决方案 > 完成第一个 Mono 后执行 Mono 列表

问题描述

完成 1 个单声道后执行单声道列表。

Mono<Project> mono1 = ...;

List<Mono<?>> publishers = new ArrayList<>();
 publishers.add(mono2);
 publishers.add(mono3);
 publishers.add(mono4);
            
if ( publishers.size() > 0 )
   Mono.zip(publishers, res->prj.id);

在这里,我想在完成 Mono1 后执行 Mono 列表。

我可以做连锁。但是,与 Mono.zip 有什么关系...?

标签: project-reactorreactor

解决方案


mono1.then(Mono.zip(publishers, res->prj.id));

查看它的 JavaDocs:

/**
 * Let this {@link Mono} complete then play another Mono.
 * <p>
 * In other words ignore element from this {@link Mono} and transform its completion signal into the
 * emission and completion signal of a provided {@code Mono<V>}. Error signal is
 * replayed in the resulting {@code Mono<V>}.
 *
 * <p>
 * <img class="marble" src="doc-files/marbles/thenWithMonoForMono.svg" alt="">
 *
 * <p><strong>Discard Support:</strong> This operator discards the element from the source.
 *
 * @param other a {@link Mono} to emit from after termination
 * @param <V> the element type of the supplied Mono
 *
 * @return a new {@link Mono} that emits from the supplied {@link Mono}
 */
public final <V> Mono<V> then(Mono<V> other) {

推荐阅读